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

Asif KhanNovember 1, 2018 at 1:27 amThank you so much Sir. Explained in an awesome manner in the aforementioned site.

Devika ClaraNovember 6, 2018 at 5:29 amI 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?

Attaullah ShahNovember 6, 2018 at 11:00 amIf 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

fitcreates 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 byasreg. 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.

Devika ClaraNovember 6, 2018 at 11:04 amAsreg is amazing , it helped me a lot on finding various variables!

Herman MeckelMay 31, 2019 at 2:15 pmHi,

This look very nice indeed. However, I cannot find an option for step size. Is that not possible with this program?

Kind Regards

Attaullah ShahMay 31, 2019 at 2:57 pmHerman Meckel

Please provide additional details on what you are proposing. Do you have some example data files?

Isiaka RaifuNovember 9, 2021 at 5:29 pmDear Sir, How can one converts annual frequency to quarterly frequency using stata?

David ToscanoFebruary 20, 2022 at 4:32 pmDear Attaullah,

I found very interesting you asreg. It would be possible to calculate the cook distance from these regressions?