Hi,
I'm new to Stata and have a regression of firm weekly return on market weekly returns: reg frim_r M_lag2 M_lag1 M_r M_lead1 M_lead2
I would like to estimate the regression by year and keep residuals for each year, so I tried the following code but ended with no observations r(2000).
Could someone please show me the right way to keep residuals by year?
Code:
gen residuals=.
levelsof year, local(level)
foreach i of local level {
reg frim_r M_lag2 M_lag1 M_r M_lead1 M_lead2 if year ==`i'
predict _res, res
replace residuals=_res if year ==`i'
drop _res
}
Kind Regards
Related Posts with Predict residuals by year
Combining two date variables into oneHi, I have a dataset with information from two different registers. The registers contain the same …
Variables not addingHere's the debugging output Code: = local mat_input"\" 1, 2, 2, rsex_matcell[2,2], rtable[1,5+2], r…
Time variable - longitudinal analysisDear Stata users, I have a query about longitudinal analysis. I originally ran growth models with …
How to make the mean of my DV variable in order to run panel without year values repeatedHello every one, I am currently estimating a model in Stata 15, and I have a dataset in which I have…
Scheme economist Code: set scheme economist for graphs puts the y axis and its label on the right hand side of the g…
Subscribe to:
Post Comments (Atom)
0 Response to Predict residuals by year
Post a Comment