Hi there,
I am running a market model by using daily returns from year 2006 to 2014 with 36 firms. I want to get the residuals of the loop regressions by firm and year.
It used to work when I use monthly returns, but not work this time!! My code is below:
gen resi=.
forval y= 2006/2014 {
forval i=1/36 {
reg dretwd marketreturn if stkcd=='i' & year=='y'
predict r if stkcd=='i' & year=='y', resid
replace resi = r if stkcd=='i' & year=='y'
drop r
}
}
Then stata shows 'i' invalid name.
Can anyone please help me out?
I also tried bysort function, stata ran 36 regressions, but I don't know how to get the residuals. egen code = group(stkcd year), bysort code : reg dretwd markereturn.
Thanks in advance.
Regards,
Jennifer
I am running a market model by using daily returns from year 2006 to 2014 with 36 firms. I want to get the residuals of the loop regressions by firm and year.
It used to work when I use monthly returns, but not work this time!! My code is below:
gen resi=.
forval y= 2006/2014 {
forval i=1/36 {
reg dretwd marketreturn if stkcd=='i' & year=='y'
predict r if stkcd=='i' & year=='y', resid
replace resi = r if stkcd=='i' & year=='y'
drop r
}
}
Then stata shows 'i' invalid name.
Can anyone please help me out?
I also tried bysort function, stata ran 36 regressions, but I don't know how to get the residuals. egen code = group(stkcd year), bysort code : reg dretwd markereturn.
Thanks in advance.
Regards,
Jennifer
Comment