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
Multilevel ModelsHi; I am runing runing linear model with four levels. I have not been able to find out what the mean…
Specifying IV with panel data, binary treatment and binary/count outcomeDear all Statalisters I am working on an application of an instrumental variable (IV) approach to a…
Creating Lagged variables with repeated valuesDear all, I wanted help in creating lagged variables when there are repeated values in the dataset.…
Twoway graph X axisHi all, Would anyone know whether there is a similar over () function such as with the graph bar (a…
Identifying the newly employed receptionist and the waitresses who joined the enterprise after the new receptionist assumed officeHi, I have the follwoing sample: Code: ssc install dataex clear input int year str6 staff_id str5 h…
Subscribe to:
Post Comments (Atom)
0 Response to Predict residuals by year
Post a Comment