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
Numerical format in regression tables using esttab/estoutDear Statalist, I am using esttab (wrapper for estout) from SSC in Stata 16.1. I am trying to expo…
Graph with bold ylabelsHi all, I am trying to get bold ylabels in a time series graph. I had success only in xlabel , exam…
Dropping Observations of Variable according to frequency of occurenceHi, I am working with the following paneldata and want to drop all observations of which I have les…
Parallel trend test for DID modelDear friends, why the test results using ttable and pstest are not consistent. Code: pstest $xli…
Dropping duplicate observations conditioned on another variableHi, I am using Stata 16.1, and have the following (general) issue. I want to drop duplicate observa…
Subscribe to:
Post Comments (Atom)
0 Response to Predict residuals by year
Post a Comment