Rolling regressions, beta, t-statistics, and SE in Stata

  • 6

Rolling regressions, beta, t-statistics, and SE in Stata


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 Khan

November 1, 2018at 1:27 am

Thank you so much Sir. Explained in an awesome manner in the aforementioned site.

Devika Clara

November 6, 2018at 5:29 am

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

predict residuals, residuals
I get the message, "last estimate not found r(301)"

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 Shah

    November 6, 2018at 11:00 am

    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

    help asreg

    Look at Example 7. It reads

    webuse grunfeld, clear
    bys company: asreg invest mvalue kstock, wind(year 10) fit

    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.

    ren _* reg1_*

    Please note that

    predict residual, residual

    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 Clara

November 6, 2018at 11:04 am

Asreg is amazing , it helped me a lot on finding various variables!

Herman Meckel

May 31, 2019at 2:15 pm


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

Kind Regards

    Attaullah Shah

    May 31, 2019at 2:57 pm

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

Leave a Reply

3 × 3 =