I am trying to run a for loop that calls [_n-1] of a variable that takes a local macro as part of its name. It produces the error message, "1 invalid name". Is this a known bug in the software? I haven't yet figured out a workaround other than manually coding each instance. An example is below.
clear
set obs 1000
gen seq = _n
gen val = runiform()
replace val=(val<=.5)
tab val
forvalues i=1/10 {
gen so_`i'=.
}
forvalues i=1/10 {
local j `i'-1
replace so_`i' = 1 if val==1 & so_`j'[_n-1]==1
}
clear
set obs 1000
gen seq = _n
gen val = runiform()
replace val=(val<=.5)
tab val
forvalues i=1/10 {
gen so_`i'=.
}
forvalues i=1/10 {
local j `i'-1
replace so_`i' = 1 if val==1 & so_`j'[_n-1]==1
}

Comment