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
Melogit model specificationHi everybody, I am currently working on the last phase of my thesis and I struggle with the last pa…
How to postfile glm output in IRR (relative risk)Dear all, I'd like to display glm model outputs using the postfile commend in stata (then transfer …
Help needed with melogitHi everybody, I am currently working on the last phase of my thesis and I struggle with the last pa…
Problem with loop and outregHello everyone, I'm having trouble with a loop when trying to use the command outreg2 to extract th…
Ologit: conditional marginal effect and semi-elastictyDear All, After estimating an ordered logit model, I want to to calculate and draw the plot of cond…
Subscribe to:
Post Comments (Atom)
0 Response to Predict residuals by year
Post a Comment