Hello everyone,
I am in desperate need so please forgive me for not reading over the rules on how to properly post lines of code/ data examples but I've been stuck on this problem for a while. I have a dataset that has variables named numerator_jun18_1...numerator_jun18_11 all the way through numerator_apr19_1...numerator_apr19_11 and the same set-up but for denominators. Im trying to do the following function:
gen score_jun18_1 = numerator_jun18_1 / denominator_jun18_1
for all 200+ variables and am trying to do so using a for loop to save myself the 200+ lines of code and possibility for human error.
I tried the following (acknowledging that I would have to do this for at least each month/year combination)
forvalues i=1/11{
local suffix cond(`i'<10, "00`i'", "0`i'")
gen score_jun18_`suffix' = numerator_jun18_`suffix' / denominator_jun18_`suffix'
}
but received the r(198) invalid name error code. Any help would be greatly appreciated
Related Posts with Using foreach or forvalues to divide two variables
Testing significance of Swamy–Arora estimator of variance component?Dear Statalisters, if I run a regression of the following form: Code: xtreg y x, re sa Is there an…
Eigenvectors in Stata (mata) vs. MatlabHi everyone, maybe this is a very silly question and I am overlooking something very, very obvious. …
SSC Install Failure: "nothing to install"Dear Statalist I recently reinstalled STATA 17 (before I was using STATA 15). Now I am facing proble…
Merge monthly to spell dataI have two datasets, in one I have an ID and a month. The second is spell data with ID, start_date, …
What causes the following error: data not spset r(459);copy http://www.stata-press.com/data/r15/homicide1990.dta ., replace copy http://www.stata-press.com…
Subscribe to:
Post Comments (Atom)
0 Response to Using foreach or forvalues to divide two variables
Post a Comment