I want to write a program in R that can let me run - 36 Months window rolling regressions on my monthly data, with at least 24 observations. This has to be done for 2000 stocks. How can I do it at a go? The equation has 2 independent variables, hence want to store 2 betas, their standard errors, intercept and standard error of regression as well.
For instance, say data starts from January 1999, then running the first regression on 36 months window from January 1999 to December 2001, requires that the output should come only if minimum 24 months data is available; otherwise that stock should be skipped for that particular regression. Next rolling regression will start from February 1999 and end at January 2002 (taking care of the minimum number of observations) and so on till March 2020. Since, it’s a monthly rolling regression, the regression output (intercept, 2 betas, their standard errors, standard error of regression) would be reported on monthly basis starting from December 2001 to March 2020.
Some genius please reply-
- How do we build such a code taking care of the minimum observations.
- Taking care that it is run for like 2000 stocks at a go.
- It is storing the required estimates in the separate columns that can be extracted in the excel.