Hello, I am trying to run regressions by companyID and year, and save the coefficients for each firm-year model as new variables in a new column right besides the other columns. There is an additional wrinkle‹ I have panel data for 1990-2010 and want to run each regression using t to t-4 only (I.e., for 2001, use only 1998-2001 years of data and i.e. for 1990 then only the data of 1990 and so on). I am new to using foreach loops and I found some prior coding on the web. I have tried to adapt it to my situation but two issues: anything.....
1. the output is staying blank
2. I have not figured out how to use the rolling four year data periods.
Here is the code I tried. Any suggestions would be much appreciated.
Code:
use paneldata.dta // the dataset I am working in generate coeff . //empty variable for coefficient foreach x of local levels { forval z = 1990/2010 { capture reg excess_returns excess_market replace coeff = _b[fyear] & _b[CompanyID] if e(sample) } }
Comment