## Introduction

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

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.

## 17 Comments

## Michel Steenhoven

October 2, 2018at 10:16 pmI am currently trying to use the command asreg to estimate rolling beta’s for a large panel data set. I believe everything is working fine but as the dataset is quite large (260000 monthly observations) the computation takes a long time. I was wondering if there is a possibility to track the computation process, to be sure the command is actually processing.

Thank you in advance for your time and effort, kind regards,

## Attaullah Shah

October 12, 2018at 4:10 pmDear Michel

I think 260000 observations should not take that much time unless your system is slow. As a suggestion, I have noted your point and shall consider this option in the next update.

## Yang Wenhao

November 1, 2018at 1:18 amFirst thank you very much for developing this wonderful package “asreg”, which is really helpful for many empirical researchers. Recently I used this package for running “Fama_Macbeth” Regressions, and I discovered some issues. When I run a regression using the command

it stores the first stage coefficients into “firststage”. But when I look into the “firststage”, I can see all the numbers are “correct”, but the variable names are somehow mismatched. For example, If I simply compute the average of all the coefficients, it should be identical to the reported 2nd stage results. But instead, I get the average coefficient of “x4” is actually recorded in “_b_x1”. And this problem does not always happen. In my case, the right-hand side variables are “aret” and “turn_ratio” . Not sure if it’s due to the specific naming of these variables.

## Attaullah Shah

November 6, 2018at 2:11 amDear Wenhao

Thanks for your feedback. I tested asreg on several datasets but did encounter the problem you are referring to. I would appreciate if you share a sample data that produces the said error.

## Mohammad Alhasham

November 6, 2018at 2:08 amhope this email finds you well. I have question regarding your asreg stata command.

I would like to run FM regression with firm and time fixed effects. I was able to do so by adding xi: before asreg. However, the option absorb is not allowed.

My question is there a way to run FM regression with asreg and also not display or report the dummy variables for firm and time fixed effect.

## Attaullah Shah

November 9, 2018at 12:30 pmAlhasham: Option absorb is not currently supported by asreg.

## Austin Moss

November 9, 2018at 12:32 pmI am attempting to use your asreg command in STATA to estimate firm and industry expected return on equity. I have used the command successfully to calculate it by industry. However, when I use the same code, but switch firmid for industryid the code will run for some of the data, but then I get an error:

I would greatly appreciate some guidance on what might be causing this error.

## Attaullah Shah

November 9, 2018at 12:36 pmAustin Moss:

Thanks for your feedback. I would appreciate if you can tell which version are you using. You can find that by typing

Second, if you can kindly share a sample of data that can generate the above error, I shall fix the error ASAP.

## Michel Steenhoven

November 9, 2018at 12:40 pmThank you for your response, unfortunately I got quite sick a few days ago so I haven’t been able to respond. I believe there was something wrong with the system indeed. I ran the regression again at a later stage and it was done quite quickly.

## Austin Moss

November 9, 2018at 12:45 pmI have attached my code and the first 150,000 observations of my sample. When I run the code as-is with irrelevant stuff highlighted out the code will calculate the ‘fit’ variables until observation #125,247. After that everything is blank/missing. This is what is giving me the biggest problem–why will it work for some of my data, but not the rest?

The data set attached is the result of running my code. To re-run the asreg code, just run the drop line under the unhighlighted out asreg code and then just run the asreg line.

The two ‘asreg’ code blocks above the currently non-highlighted one work for industryid (industryfe) but not firmid (gvkey or firmfe). However, the error usually occurs later in the data set and would be hard to transfer the whole data set via email. I am hoping that the solution for the above will also be the solution for the other blocks of code.

## Attaullah Shah

December 10, 2018at 10:27 pmAustin Moss: asreg version 3.2 is now available for download from SSC (thanks to Kit Baum). This version fixes a minor bug in one of the Mata functions. Mata function ASREG4s0f1() would throw an error if the option fit was used on a dataset that did not have enough observations for estimating a regression. To update,

## Ventsi Stamenov

December 4, 2018at 11:07 amDear Dr. Shah:

I am trying to apply your asreg command using Fama-Macbeth.

Is it possible in your regression to test the equality of the coefficients for

`dep1=dep2.`

I know that if you use the regressioStatamand in stata you can test whether

`dep1=dep2`

.How would you advise to do the dep1=dep2 in a Fama-Macbeth setting?

Thanks much,

## Attaullah Shah

December 10, 2018at 10:25 pmVentsi: I have not tested equality of coefficients before and hence cannot comment on this.

## Ventsi Stamenov

December 10, 2018at 10:28 pmThank you sir. How about reporting the standard errors and the degrees of freedom from the first stage. Is it possible to extract them?

## Chris H Zhang

March 27, 2019at 10:48 amHi professor,

I’m from STATALIST and would like to ask you a question regarding “asreg”.

I used an old version of asreg function (used it roughly a year ago), to calculate by each stock(index) the residual value of regression from a panel data.

Above us basically what I did.

I recently realized that the function has been updated. I don’t know what version I used back then to execute the above codes. just wondering whether the following updates would affect the results I got? Do I have to redo everything I did?

Thanks

## Attaullah Shah

March 27, 2019at 10:49 amChris H ZhangThe updates to asreg have not changed anything fundamental. The calculations of the regression coefficients remain unchanged, therefore, the calculations of the older and newer versions of asreg are still the same.

## Dimitri

April 15, 2019at 10:07 pmDear Sir,

Thank you for contributing asreg to the community. Is there any immediate plans to implement weighted FM regressions using aweight? Xtfmb supports weighted FM regressions, but asreg does not.

Given that asreg is much faster than xtfmb, it would be wonderful if you could add the functionality to your next release. Any chance of seeing this in the very near future?

Thank you.