Tag Archives: asreg

  • 0

asreg: Get standard errors of the first stage regression of the Fama and MacBeth (1973) Procedure in Stata

Category:Uncategorized Tags : 

In the following example, we shall use asreg that can be installed from SSC by typing the following line in Stata command window

ssc install asreg

 

The problem

Let’s say that we wish to report different regression statistics from Fama and MacBeth (1973) regression such the standard errors of variables. Using the fmb option, asreg can efficiently estimate FMB regression. Further, it reports the regression coefficients of the first stage regression when option first is used with the option fmb.  However, it does not report other regression statistics. 

 

The solution

The good news is that we can still find different regression components using asreg. Since the first stage regression of the FMB procedure is the cross-sectional regression, we can use the bysort period prefix with asreg.

 

An example

Let us use the grunfeld data and estimate the FMB regression in the usual manner.

webuse grunfeld, clear
asreg invest mvalue kstock, fmb first

First stage Fama-McBeth regression results

  +------------------------------------------------------------+
  | _TimeVar   _obs       _R2   _b_mva~e   _b_kst~k      _Cons |
  |------------------------------------------------------------|
  |     1935     10   .865262    .102498   -.001995    .356033 |
  |     1936     10   .696394    .083707   -.053641    15.2189 |
  |     1937     10   .663763    .076514    .217722   -3.38647 |
  |     1938     10   .705577    .068018    .269115   -17.5819 |
  |     1939     10   .826602    .065522    .198665   -21.1542 |
  |     1940     10   .839255    .095399    .202291   -27.0471 |
  |     1941     10   .856215    .114764    .177465   -16.5195 |
  |     1942     10   .857307    .142825    .071024   -17.6183 |
  |     1943     10   .842064     .11861    .105412   -22.7638 |
  |     1944     10   .875515    .118164    .072207   -15.8281 |
  |     1945     10   .906797    .108471    .050221   -10.5197 |
  |     1946     10   .894752    .137948    .005413   -5.99066 |
  |     1947     10   .891239    .163927   -.003707   -3.73249 |
  |     1948     10   .788823    .178667   -.042556    8.53881 |
  |     1949     10   .863257    .161596   -.036965    5.17829 |
  |     1950     10   .857714    .176217   -.022096   -12.1747 |
  |     1951     10   .873773    .183141   -.112057    26.1382 |
  |     1952     10   .846122    .198921   -.067495    7.29284 |
  |     1953     10   .889261    .182674    .098753   -50.1525 |
  |     1954     10    .89845    .134512    .331375   -133.393 |
  |---------------------------------------------------------
Mean | 1944.5    10    .836907   .130605    .072958    -14.757 |
  +------------------------------------------------------------+
Fama-MacBeth (1973) Two-Step procedure           Number of obs     =       200
                                                 Num. time periods =        20
                                                 F(  2,    19)     =    195.04
                                                 Prob > F          =    0.0000
                                                 avg. R-squared    =    0.8369
------------------------------------------------------------------------------
             |            Fama-MacBeth
      invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      mvalue |   .1306047   .0093422    13.98   0.000     .1110512    .1501581
      kstock |   .0729575   .0277398     2.63   0.016     .0148975    .1310176
       _cons |  -14.75697   7.287669    -2.02   0.057    -30.01024     .496295
------------------------------------------------------------------------------

 

An alternate way to first-stage

bys year: asreg invest mvalue kstock, se
bys year: keep if n == _N
+-------------------------------------------------------------------------------------------------------------+
| year _Nobs _R2 _adjR2 _b_mvalue _b_kstock _b_cons _se_mv~e _se_ks~k _se_cons |
|-------------------------------------------------------------------------------------------------------------|
| 1935 10 .86526202 .82676546 .10249786 -.00199479 .35603339 .0157931 .2148591 23.82794 |
| 1936 10 .69639369 .60964903 .08370736 -.05364126 15.218946 .0211982 .4125528 49.72796 |
| 1937 10 .6637627 .56769491 .0765138 .21772236 -3.3864706 .0218952 .4745161 62.14382 |
| 1938 10 .70557727 .62145649 .06801777 .26911462 -17.581903 .0220019 .2076121 33.62243 |
| 1939 10 .82660153 .77705911 .06552194 .19866456 -21.154227 .0131751 .1563955 29.10151 |
|-------------------------------------------------------------------------------------------------------------|
| 1940 10 .83925512 .79332801 .095399 .20229056 -27.047068 .0171077 .2206074 42.49812 |
| 1941 10 .85621485 .81513338 .11476375 .17746501 -16.519486 .0197202 .2338307 47.43406 |
| 1942 10 .85730699 .81653756 .14282513 .07102405 -17.618283 .0246973 .1966943 43.85369 |
| 1943 10 .84206394 .79693935 .11860951 .10541193 -22.763795 .0207092 .1887016 46.8604 |
| 1944 10 .87551498 .83994783 .11816422 .07220719 -15.828145 .0169881 .1537212 41.84578 |
|-------------------------------------------------------------------------------------------------------------|
| 1945 10 .90679731 .88016797 .1084709 .05022083 -10.519677 .0133214 .1254533 35.10524 |
| 1946 10 .89475165 .8646807 .13794817 .00541339 -5.9906571 .018637 .1600683 45.73243 |
| 1947 10 .89123943 .86016498 .16392696 -.00370721 -3.7324894 .0280743 .1285463 37.80575 |
| 1948 10 .7888235 .72848735 .1786673 -.04255555 8.5388099 .0463983 .1661775 52.39133 |
| 1949 10 .86325678 .82418728 .16159617 -.03696511 5.1782863 .0346516 .1268614 41.07802 |
|-------------------------------------------------------------------------------------------------------------|
| 1950 10 .85771384 .81706065 .17621675 -.02209565 -12.17468 .0393216 .1361792 46.6222 |
| 1951 10 .87377295 .83770808 .18314051 -.11205694 26.138157 .0358898 .1486738 53.00348 |
| 1952 10 .84612242 .80215739 .19892081 -.06749499 7.2928402 .052286 .1906835 67.84544 |
| 1953 10 .88926056 .85762072 .18267385 .09875335 -50.152546 .058579 .2164437 77.91569 |
| 1954 10 .89845005 .86943578 .13451162 .33137459 -133.39308 .0704524 .1932826 76.18067 |
+-------------------------------------------------------------------------------------------------------------+

 

Explanation

In the above lines of code, we estimated a yearly cross-sectional regression with the option se to report the standard errors. Then we retained just one observation per year and deleted duplicates. The results are the same as reported by the option first in the fmb regression, with the only difference that we have now additional regression statistics.


  • 1

Stata Rolling command vs asreg for rolling regressions: Similarities and differences

Category:Stata Programs Tags : 

Karina van Kuijk asked the following question:

Question: 

I need to calculate the factor sensitivity of firms to ultimately sort portfolio’s based on this factor. I have found the asreg Stata code on your website and I was wondering if this code would be useful for my purpose. However, if I compare the rolling Stata code with your aserg program on a small dataset, I won’t get the same results.

Answer 

The key difference between the Stata’s official rolling command and asreg [see this blog entry for installation] is in their speeds. asreg is an order of magnitude faster than rolling.  There are other differences with respect to how these two calculate the regression components in a rolling window.  For example, rolling command will report statistics when the rolling window reaches the required length while asreg reports statistics when the number of observations is greater than the parameters being estimated. Therefore, if we have one independent variable and use a rolling window of 10 periods, rolling will report statistics from the 10th period in the dataset. However, asreg will report statistics from the 3rd observation (two parameters here, the coefficient of the independent variable and the intercept).  To make the results of asreg at par with the rolling command, let us use an example:

 

Example

Let us use the grunfeld data that has 10 companies and 20 years of time series for each company. We shall use the variables invest as dependent variable and mvalue as the independent variable.  Therefore, the rolling command will look like:

 

webuse grunfeld

rolling _b, window(10) saving (beta, replace): reg invest mvalue

The results from the rolling command are reported below only for the first company

 

company start end _b_cons _b_mvalue
1 1935 1944 186.5406 .0562316
1 1936 1945 196.1084 .0573704
1 1937 1946 106.4769 .0847188
1 1938 1947 53.12083 .1053145
1 1939 1948 364.5426 .0359897
1 1940 1949 372.5457 .0400371
1 1941 1950 360.8489 .04835
1 1942 1951 213.7943 .090357
1 1943 1952 119.8572 .1195415
1 1944 1953 -284.6031 .2229699
1 1945 1954 -496.6066 .2841584

 

To find similar results with asreg, we shall type:

bysort company: asreg invest mvalue, wind(year 10)

 

asreg generated the following results for the first company:

 

company year _Nobs _R2 _adjR2 _b_cons _b_mvalue
1 1935 . . . . .
1 1936 . . . . .
1 1937 3 .98568503 .97137006 192.3812 .04135324
1 1938 4 .91957661 .87936492 129.06727 .05411168
1 1939 5 .86795099 .82393465 129.91674 .05233687
1 1940 6 .69944952 .6243119 108.59266 .06102699
1 1941 7 .54085608 .4490273 91.235677 .06942586
1 1942 8 .31250011 .19791679 182.86065 .05101677
1 1943 9 .25355654 .14692176 197.08754 .05052367
1 1944 10 .24298452 .14835759 186.54064 .05623158
1 1945 10 .20582267 .10655051 196.10839 .05737045
1 1946 10 .29515806 .20705282 106.47691 .0847188
1 1947 10 .3728928 .2945044 53.120829 .10531451
1 1948 10 .05894158 -.05869073 364.54258 .03598974
1 1949 10 .1461912 .0394651 372.54574 .04003715
1 1950 10 .18946219 .08814496 360.84887 .04834995
1 1951 10 .41646846 .34352702 213.79429 .09035704
1 1952 10 .38796888 .31146499 119.85717 .11954148
1 1953 10 .69741758 .65959478 -284.60313 .22296989
1 1954 10 .67138447 .63030752 -496.6066 .28415839

 

As mentioned above, asreg does not wait for the full window to get the required number of period. Therefore, results from the rolling command and asreg start to match only from the 10th observation,  i.e., the year 1944. If you like asreg to ignore observation unless the minimum number of periods are available, you can use the option min. So to match the results with the rolling command, we can type:

bysort company: asreg invest mvalue, wind(year 10) min(9)

 

and there you go, asreg produces the same coefficients as the rolling command, with blistering speed.

 

Please do cite asreg in your research

 

In-text citation

Rolling regressions were estimated using asreg, a Stata program written by Shah (2017).

 

Bibliography

Shah, Attaullah, (2017), ASREG: Stata module to estimate rolling window regressions. Fama-MacBeth and by(group) regressions, https://EconPapers.repec.org/RePEc:boc:bocode:s458339.