Dear Statalist members,
Could you please help me figure out what's wrong with my loop below?
I define a variable "i" for a loop, and Stata complains that this variable does not exist..
tempname myresults
postfile `myresults' fund intercept using myresults.dta
local N = _N
quietly foreach v of varlist T {
forval i=37/N {
gen temp = `v'[_n] if _n<i & _n>=i-36
gen temp2 = mkt[_n] if _n<i & _n>=i-36
xi: regress temp temp2
post `myresults' (`v') (`=_b[_cons]')
drop temp
drop temp2
}
}
postclose `myresults'
I receive an error: i not found
r(111);
How can it be if I define this variable at the beginning of the loop?
Thanks a lot!
Could you please help me figure out what's wrong with my loop below?
I define a variable "i" for a loop, and Stata complains that this variable does not exist..
tempname myresults
postfile `myresults' fund intercept using myresults.dta
local N = _N
quietly foreach v of varlist T {
forval i=37/N {
gen temp = `v'[_n] if _n<i & _n>=i-36
gen temp2 = mkt[_n] if _n<i & _n>=i-36
xi: regress temp temp2
post `myresults' (`v') (`=_b[_cons]')
drop temp
drop temp2
}
}
postclose `myresults'
I receive an error: i not found
r(111);
How can it be if I define this variable at the beginning of the loop?
Thanks a lot!
Comment