asreg is a Stata program, written by Dr. Attaullah Shah. The program is available for free and can be downloaded from SSC by typing the following on the Stata command window:

ssc install asreg

asreg was primarily written for rolling/moving / sliding window regressions. However, with the passage of time, several useful ideas were conceived by its creator and users. Therefore, more features were added to this program. The primary uses of asreg can be summarized under the following three headings:

## Speed Efficiency

asreg is an order of magnitude faster than estimating rolling window regressions through conventional methods such as Stata loops or using the Stata’s official *rolling* command. asreg has the same speed efficiency as asrol. All the rolling window calculations, estimation of regression parameters, and writing of results to Stata variables are done in the Mata language. Similarly, estimating Fama and MacBeth(1973) regression through asreg is several times faster than other available options.

## Uses

asreg can be used for the following purposes. Click the following links for further details.

1.Rolling window regression

2. Recursive window regressions

3. by-group regressions

3.2 by-groups regressions with residuals and fitted values

4. Fama-MacBeth (1973) regressions

4.2 FMB regression – what, how and where

4.3 FMB regressions with 25-portfolios – An example

5. Rolling window regression with Newey-West standard errors

6. Rolling window fitted values and residuals

7. Getting rolling window t-statistics

### Questions / Answers

Question: How can I get similar results as produced by the Stata’s *rolling* command

Answer: See a detailed answer here in this post

Angela TorresFebruary 28, 2021 at 11:14 pmDear Attaullah Shah,

I wonder if there is a way to add Driscoll-Kraay standard errors to perform rolling regressions using fixed effects in Stata?

I know you can use Newey and robust errors with this code, but is there a way to add Driscoll-Kraay standard errors?

clear all

set more off

webuse grunfeld,clear

xtset company year

tab company, gen(company_)

asreg invest mvalue kstock company_*, wind(year -7 0) robust

//or

asreg invest mvalue kstock company_*, wind(year -7 0) newey(2)

Thank you very much for your help!

TYJuly 10, 2021 at 12:30 amI have a question about how asreg handles missing values for the dependent variable. For example, if I am estimating CAPM betas using a rolling regression, then asreg will produce a missing value for a beta estimate if my current dependent variable (current return in this case) is missing. However, If I’m using 12 months of rolling data to estimate beta but only require a minimum of 10 months, then I don’t necessarily want a missing value for my beta estimate if my current return is missing, since I only need 10 months of data. Is there a way to adjust asreg so that it won’t lead to a missing value for my beta estimate if the current return is missing?

AHMEDApril 5, 2022 at 12:47 amHello,

How do I get studentized residuals using asreg. If I use the predict button, it says last estimates not found

Attaullah ShahApril 28, 2022 at 6:29 pmstudent zed residuals are not possible with asreg.

RajMay 1, 2022 at 8:39 pmHello, I am using asreg command. I have a large sample of about 500 firms (identified as ‘gvkey’ with data from 1986 to 2021. For each year (i.e., ‘fyear) starting with 2022, I need to run a firm-by-firm recursive regression with a minimum of 10 observations for each firm. I am interested in getting the residuals. I used the following command:

bys gvkey: asreg y1 x1 x2 x3, wind(fyear 1000) exclude(year 0 0) min(10) residuals

Stata responses I receive are:

Error in the option exclude!

option residual not allowed

Can you kindly assist me?

Iyengar

RajMay 1, 2022 at 8:41 pmTypo: Instead of 2022 read ‘2002’.

Thanks.