asreg can easily estimate rolling regressions, betas, t-statistics and SE in Stata. To understand the syntax and basic use of asreg, you can watch this Youtube video. In this post, I show how to use asreg for reporting standard errors, fitted values, and t-statistics in a rolling window.
To install asreg, type the following on the Stata command window
ssc install asreg
Report standard errors and fitted values
We shall use the grunfeld data set for our examples. Using a rolling window of 15 observations, let us fit a regression model where our dependent variable is invest and independent variables are mvalue and kstock. We shall estimate the rolling regression separately for each company, therefore, we shall use the prefix bys company :
Please note that option se and fit are used for reporting standard errors and fitted values, respectively.
webuse grunfeld, clear bys company: asreg invest mvalue kstock, wind(year 15) fit se
Find t-statistics in the rolling window
Once we have the standard errors and coefficients, we can generate t-statistics by dividing respective coefficients on their standard errors. Therefore, to find t-values for the variable mvalue and kstock, we can generate new variables:
gen t_mvalue = _b_mvalue / _se_mvalue gen t_kstock = _b_kstock / _se_kstock
Thank you so much Sir. Explained in an awesome manner in the aforementioned site.
I would like to ask can I use the asreg to find the residuals in a rolling regression? I have to estimate two regressions. The 1st data after I regressed it, I could not find the residuals by typing
I would also like to find residuals for the 2nd regression. Do you have any recommendations to solve this problem so I could find the residuals in rolling regression?
If you read the help file, it provides some examples on finding residuals in a rolling window. Type the following in the Stata command window
Look at Example 7. It reads
The above codes estimate a rolling window regression of 10-periods and the option fit creates two additional variables by the names _fitted _residuals. As the names signify, these variables report rolling window fitted and residual values. If you have another regression and want to estimate residuals for that too, then you need to first rename the variables created by asreg. For example, type this code for renaming all variables.
Please note that
command does not work with asreg as this command works only with Stata’s regression commands.
This YouTube video can also be helpful for you.
Asreg is amazing , it helped me a lot on finding various variables!
This look very nice indeed. However, I cannot find an option for step size. Is that not possible with this program?
Please provide additional details on what you are proposing. Do you have some example data files?
Dear Sir, How can one converts annual frequency to quarterly frequency using stata?
I found very interesting you asreg. It would be possible to calculate the cook distance from these regressions?