Hi,

I have an unbalanced panel dataset with daily (financial) data for ±500 companies.

The following is what I'm trying to execute in Stata:
  • Running a rolling window fixed effects (fe) regression over 51 days;
    • per day and company in my dataset, and;
      • FIRST) for all the companies,
      • SECOND) for the companies with "1" as dummy variable value,
      • THRID) for the companies with "0" as dummy variable value.
  • Per estimated fe regression, predict the residuals and save them as a new variable in the existing dataset
I believe that each observation will be used 51 times and that only the last time an observation is used, it will be saved/'remain' in the data (and not be overwritten by the next fe regression estimates). I expect that Stata starts the rolling regressions with the oldest data and 'roll' towards the the most recent date. However, and if this is true, I'd like Stata to start regressing on the most recent date available for a company and 'roll' towards the oldest observations.

The eventual goal is to have an overview of the independent variable's coefficients on a day as calculated over the preceding 51 days and with the corresponding residuals as well.

My attempts:
First: I tried the 'rolling' command, but with +500 companies and a dataset covering ±2400 days this is taking too long.
Second: the asreg command isn't supporting 'xtreg' commands and thus doesn't allow me to run a rolling fe regression.
Third: using a loop with 'foreach'. The code I'm written is included below, but yields an error saying 'insufficient observations'.
Code:

xtset SedolID NDaysSince

levelsof SedolID, local(IDlist)
foreach i of local IDlist {
xtreg y x x x x x if NDaysSince>`i' & NDaysSince<52+`i' & Dummy_Var==1, fe
predict residual_`i', resid
estsave reg_`i'
}

My Questions:
  • Is it possible to have Stata regress fe with rolling window starting with the most recent date and 'rolling' toward older observations? How to I get Stata to compute the above described regressions?
Please let me know if additional information is needed, thank you,
Christian