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
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
How to cite?
If you have used asreg in your research, please cite it as follows:
In text : Regressions were estimated using the asreg package of Stata, written by Shah (2017).
Bibliograph
Shah, Attaullah (2017) “ASREG: Stata module to estimate rolling window regressions, Fama-MacBeth and by(group) regressions,” Statistical Software Components S458339, Boston College Department of Economics, revised 04 Jul 2023.
Dear 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!
I 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?
Hello,
How do I get studentized residuals using asreg. If I use the predict button, it says last estimates not found
student zed residuals are not possible with asreg.
Hello, 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
Typo: Instead of 2022 read ‘2002’.
Thanks.
Hello,
I want to use asrol for the calculation of the synchronization coefficients (correlation) year by year. could you tell me more about the command to use? do I have to use the same command (gap command type)?
Hello Prof Attaullah,
Can asreg be used to model conditional volatility of an a variable say inflation , for example GARCH(1 1) or EGARCH(1 1) estimation of inflation for a rolling window of say past 3 years monthly data for panel of countries?
Thank you for consideration
No, asreg uses OLS and can report different types of standard errors.
Dear Attaullah Shah,
To begin with, thank you for creating this command.
I want to calculate betas using one year’s worth of daily returns and I want the year to have at least 150 days.
I am using CRSP daily data and my sample starts from 04jan1993
I applied the following.
gen day=day(date)
bys PERMNO: asreg excess_ret MktRF, window (day 252) min(150)
It works, but I get values for every day in the sample even the very first day, which I imagine I shouldn’t given that I specified min(150).
What am I missing?
Thanking you in advance.
There seems to be duplicates in your data, I do not see the problem you have referred to when I use the following dummy data
Hi Attaullah, thanks for the package. I noticed that the time labels from the first stage regression of the Fama-Macbeth regression is messed up. It seems to be an easy fix, but I am not very familiar with STATA codes. Could you look into this? I want to plot the first stage coefficients with the time variable on the x-axis, but this error complicates this task. Thanks again.
***CODES:
webuse grunfeld
xtset company year
asreg invest mvalue, fmb first
***RESULTS:
First stage Fama-McBeth regression results
+——————————————————-+
| year _obs _R2 _adjR2 _b_mva~e _Cons |
|——————————————————-|
| 1935 10 .86526 .848418 .102534 .205841 |
| 1935 10 .69566 .657618 .084087 10.8287 |
| 1935 10 .65365 .610357 .078748 15.9915 |
| 1935 10 .634906 .589269 .078951 10.6719 |
| 1935 10 .786631 .75996 .07066 4.19547 |
| 1935 10 .819947 .79744 .099193 .778946 |
| 1935 10 .844383 .824931 .119614 9.58541 |
| 1935 10 .854649 .83648 .146412 -6.30129 |
| 1935 10 .835023 .814401 .121626 -3.24821 |
| 1935 10 .871591 .85554 .118681 -1.0518 |
| 1936 10 .904664 .892747 .109082 -.206266 |
| 1936 10 .894734 .881576 .138123 -4.9362 |
| 1936 10 .891227 .87763 .163409 -4.39361 |
| 1936 10 .786845 .760201 .170411 1.09255 |
| 1936 10 .861598 .844298 .154097 -2.14842 |
| 1936 10 .857179 .839326 .17149 -16.4937 |
| 1936 10 .863529 .84647 .162703 3.02421 |
| 1936 10 .843368 .823789 .183678 -6.36933 |
| 1936 10 .885967 .871713 .206258 -29.2206 |
| 1936 10 .855808 .837784 .242492 -74.9082 |
|——————————————————-|
Mean | 1935 10 .825331 .803497 .136112 -4.64516 |
Thanks for reporting this. I have fixed the issue. The updated version can be installed from the SSC.
Wonderful! Works perfectly on my end as well. Thanks for the quick reply. Hope you enjoy the Summer.