Fama and MacBeth (1973) Fastest regression in Stata

The Fama-McBeth (1973) regression is a two-step procedure . The first step involves estimation of N cross-sectional regressions and the second step involves T time-series averages of the coefficients of the N-cross-sectional regressions. The standard errors are adjusted for cross-sectional dependence. This is generally an acceptable solution when there is a large number of cross-sectional units and a relatively small time series for each cross-sectional unit. However, if both cross-sectional and time-series dependencies are suspected in the data set, then Newey-West consistent standard errors can be an acceptable solution.

Estimation Procedure


The Fama-McBeth (FMB) can be easily estimated in Stata using asreg package.  Consider the following three steps for estimation of FMB regression in Stata.

1.  Arrange the data as panel data and use xtset command to tell Stata about it.

2.  Install asreg from ssc with this line of code:

ssc install asreg

3. Apply asreg command with fmb option

An Example


We shall use the grunfeld dataset in our example. Let’s download it first:

webuse grunfeld

This data is already xtset, with the following command:

xtset company year

Assume that we want to estimate a FMB regression where the dependent variable is invest and independent variables are mvalue and kstock. Just like regress command, asreg uses the first variable as dependent variable and rest of the variables as independent variables. Using the grunfeld data, asreg command for FMB regression is given below:

asreg invest mvalue kstock, fmb
 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
 ------------------------------------------------------------------------------

Newey-West standard errors


If Newey-West standard errors are required for the second stage regression, we can use the option newey(integer).  The integer value specifies the number of lags for estimation of Newey-West consistent standard errors. Please note that without using option newey, asreg estimates normal standard errors of OLS. This option accepts only integers, for example newey(1) or newey(4) are acceptable, but newey(1.5) or newey(2.3) are not. So if we were to use two lags with the Newey-West error for the above command, we shall type;

asreg invest mvalue kstock, fmb newey(2)
Fama-MacBeth Two-Step procedure (Newey SE)            Number of obs     = 200
(Newey-West adj. Std. Err. using lags(2))             Num. time periods = 20
                                                      F( 2, 19)         = 39.73
                                                      Prob > F          = 0.0000
                                                      avg. R-squared    = 0.8369
---------------------------------------------------------------------------------
        |            Newey-FMB
 invest | Coef.      Std. Err. t       P>|t|     [95% Conf. Interval]
-------------+-------------------------------------------------------------------
 mvalue | .1306047  .0150138   8.70    0.000    .0991804   .1620289
 kstock | .0729575  .0375046   1.95    0.067    -.0055406   .1514557
 _cons  | -14.75697  8.394982  -1.76   0.095    -32.32787   2.813928
---------------------------------------------------------------------------------


For some reasons, if we wish to display the first stage N – cross-sectional regressions of the FMB procedure, we can use the option first. And if we wish to save the first stage results to a file, we can use the option save(filename). Therefore, commands for these options will look like:

asreg invest mvalue kstock, fmb newey(2) first

asreg invest mvalue kstock, fmb newey(2) first save(FirstStage)

                               First stage Fama-McBeth regression results

_TimeVar _obs _R2 _b_mva~e _b_kstock _Cons
1935 10 .865262 .1024979 -.0019948 .3560334
1936 10 .6963937 .0837074 -.0536413 15.21895
1937 10 .6637627 .0765138 .2177224 -3.386471
1938 10 .7055773 .0680178 .2691146 -17.5819
1939 10 .8266015 .0655219 .1986646 -21.15423
1940 10 .8392551 .095399 .2022906 -27.04707
1941 10 .8562148 .1147638 .177465 -16.51949
1942 10 .857307 .1428251 .071024 -17.61828
1943 10 .842064 .1186095 .1054119 -22.7638
1944 10 .875515 .1181642 .0722072 -15.82815
1945 10 .9067973 .1084709 .0502208 -10.51968
1946 10 .8947517 .1379482 .0054134 -5.990657
1947 10 .8912394 .163927 -.0037072 -3.732489
1948 10 .7888235 .1786673 -.0425555 8.53881
1949 10 .8632568 .1615962 -.0369651 5.178286
1950 10 .8577138 .1762168 -.0220956 -12.17468
1951 10 .873773 .1831405 -.1120569 26.13816
1952 10 .8461224 .1989208 -.067495 7.29284
1953 10 .8892606 .1826739 .0987533 -50.15255
1954 10 .8984501 .1345116 .3313746 -133.3931

More on FMB regression

FMB regression – what, how and where

FMB regressions with 25-portfolios – An example

Rolling window statistics with asrol


38 Comments

Dr. Hassan Raza

March 24, 2019at 11:25 am

Dear Sir,

Hope you are fine and in good health. I am one of your student from Bara-Gali workshop, I am applying Fama and Macbeth regression on Pakistan Stock exchange firms on monthly data (Data sheet attached herewith). I have some queries regarding asreg

asreg ex_firm_re ex_mkt_re , fmb

, this code provides the second stage Fama and Macbeth results, but as I check the first stage it only shows me … (Dots) in the first process, why?
When same procedure is applied for Global market excess return, it omitted the same variable and provide results for only constant term why?

I am sorry for your precious time. Please also let me know about any coming workshop on Stata.

    Attaullah Shah

    March 24, 2019at 11:35 am

    A bit of code was missing which I have added. The updated version can be downloaded from SSC a week or so. However, at the moment, there is a workaround and you do not need to wait for the updated version. So just add the save option to the line and it will work as expected. Bonus yet, you can the first stage regression ouptut in a file.

    asregc ex_firm_re ex_mkt_re , fmb first seve(first)

Dr. Hassan Raza

March 24, 2019at 11:43 am

Thank you so much sir. What about when I regressed against excess global premium it omitted the said variable and only report constant. Sorry for your time.

    Attaullah Shah

    March 24, 2019at 11:45 am

    Since the FMB regression is a cross-sectional regression, estimated in each time period, therefore, the variables need to vary across entities. Your gspc_return variable seems to be constant within a given period. See the case of the first month:

    edit if month_year == 487

    and you shall see that all the values of this variable are the same within the given month, and is also the case with other months; therefore, the regression does not find any variation in the dataset to fit the model.

Mathias

April 12, 2019at 10:37 am

Dear Attaullah Shah,

Is the F value in asreg Y X, fmb by(time) defined as the time-series average of the F values from the cross-sectional regressions?

Thank you for your asreg package, which is very useful to me.

Regards,
Mathias

    Attaullah Shah

    April 13, 2019at 11:26 am

    Mathias
    The F-value is directly reported from the mvreg regression that is estimated for all the cross-sectional regressions of the first stage of FMB

Anonymous

April 26, 2019at 6:26 pm

Dear Attaullah Shah,

Is it possible to generate the adj. R^2? Thank you!

Monica

April 26, 2019at 6:28 pm

Dear Attaullah Shah,

Is it possible to derive the adj. R^2 variable? Thank you.

Marie

May 9, 2019at 3:01 pm

Hey,

I am a little bit unsure how I should understand the procedure.
Does this mean that you estimate one regression for each year across the firms? Or do you estimate one regression on each firm (even though some may be unbalanced, thus some periods may be missing both in the long time interval both also in consecutive periods), and then take the average of this coefficient for each year given the firm present in each period.

Thank you!

    Attaullah Shah

    May 9, 2019at 4:07 pm

    Marie
    To understand the FMB procedure, you should first study Fama and MacBeth(1973) paper and relevant literature elsewhere. The procedure estimates a cross-sectional regression in each period in the first step. And in the second step, all those cross-sectional coefficients are averaged across time periods. The standard errors are adjusted for cross-sectional dependence, see Fama and MacBeth(1973) paper for more details.

    Reference
    Fama, E. F., & MacBeth, J. D. (1973). Risk, return, and equilibrium: Empirical tests. Journal of Political Economy, 81(3), 607-636.

Thomas A.

May 14, 2019at 5:03 pm

Dear Attaullah Shah,

First of all, thank you for your website it has been great support to me.
However, I have problems using the fmb on my data set. I have a panel dataset with monthly fund returns from which I wanted to get the average alpha using the fama french 3-factor model. When I set xtset Fund Time I always get omitted variables. The paper I am referring to is doing the same, but does not get omitted variables? Do you have an idea what I’m doing wrong?
I am using: asreg fund_return mktfrf smb hml, fmb

    Attaullah Shah

    May 15, 2019at 2:01 am

    Thomas
    A similar issue is reported every now and then on Statalist. A more recent thread on the Statalist discusses the issue of variables that are invariant cross-sectionally. Please go there and read the thread.

Thomas A.

May 15, 2019at 3:53 pm

Thank you for the answer,
not sure if I got it right. The Fama-French factors are panel invariant variables and thus the variables get omitted. But why are so many research papers state that they are using FMB in this context since they all face the same problem? Is there a step to perform before using asreg fmb to get variant variables or would an xtset to time id help?

    Attaullah Shah

    May 15, 2019at 4:18 pm

    Thomas
    We would be interested in posting relevant text from such papers here. If you

    xtset time id

    this will cause asreg to first estimate a time series regression for each company and then report the averages of those time series regressions.

Thomas A.

May 15, 2019at 8:19 pm

Happy to share that paper with you, but since it is a working paper which is not published yet I would prefer to send in private. Just leave me an e-mail adress where to send it to.

    Attaullah Shah

    May 16, 2019at 9:34 pm

    Thomas
    What I meant was to share text from the mentioned papers that use Fama and French factors in Fama and MacBeth (1973) regression.

Thomas A.

May 16, 2019at 10:44 pm

Atthullah
here is a link to one paper: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3081166
I am referring to the description of table 2 in specific.

    Attaullah Shah

    May 17, 2019at 1:03 am

    On page 9 of the mentioned paper, the author writes
    “Table 2 shows by-fund average fund performance with Fama and MacBeth (1973) standard errors based on monthly returns.”

    Therefore, the author does not estimate cross-sectional regressions in the first stage of the Fama and MacBeth (1973) procedure. Rather, he estimates time series regression for each fund, and then finds averages across all firms.

Antonio

May 25, 2019at 10:09 pm

Dear Sir,
I was wandering how to run a Fama and MacBeth regression over 25 Portfolios.
In accordance with your code, the first variable needs to be the dependent variable while the following variables are considered as independent variables.. Basically I would like to calculate the risk premium of a factor over the 25 value ans size sorted portfolios. Therefore in my case i would have more dependent variables and just one dependent variable.
Thanks for your avialability

    Attaullah Shah

    May 26, 2019at 1:17 am

    Antonio
    To answer your question, I have written this post.

Antonio

May 26, 2019at 10:19 pm

Dear Sir,
thanks for your detailed answer but unfortunately your example does not fit mine dataset.
In my dataset the independent variable ( for example the market excess return) has the same value for each Portfolio while in your case the independent variable has different value for each portfolio. In fact when I try to use your code I do not get any coefficient for the market risk premium.
Thanks again for your availability

    Attaullah Shah

    May 26, 2019at 11:06 pm

    Yes, cross-sectionally invariant variables will be omitted in Fama and MacBeth regressions. There was a lengthy discussion on this issue on Statalist, it might be helpful for you. The post can be read here

Marie

May 28, 2019at 6:43 pm

Thank you for the reply. I have an additional question. Do you know if you can obtain reliable estimates when using this approach on T=27 where the first 7 periods have between 60-150 observations in each while the later periods have between 200 and 600 yearly observations. I was thinking of cutting the period, because the reliability on the first 7 periods may influence the total estimate. I found that my results are significantly different when using T=27 and T=20 due to the limited data in the first years. However, I was unable to find more information online on this issue.

I would be really thankful if you had any articles in mind discussing this issue.

Thank you for your time.

Marie

May 28, 2019at 7:58 pm

Thank you for the reply.

I have another concern that I would like to ask you about. I have a panel dataset were T=27. However, in 7 of the years I only have 62-128 observations while I have 150-600 yearly observations in the following 20 years. I am wondering if you know of any problems with small T and then small number (/increasing number of N). I have not been able to find articles concerning this issue so far.

I tried using FmB across the entire 27 years, however the results is significantly different from the result I obtain when only using the T=20. So I am looking for any critique that may be of putting relatively large weight on the 7 years (weight 26%) to betas estimated on only approximately 9% of the total firm years.

Thank you for the help.

Juan

June 3, 2019at 3:47 pm

Hi professor, thank you so much for your post and help overall. I have a question however, regarding the time period of the formation for the betas. How do you specify how many days, months or years do you want for the rolling betas to form?

Thanks,

Juan

Jon

June 9, 2019at 1:20 am

Dear Attulah,
I am investigating the relationship between Abnormal Google Search Volume and Abnormal Returns. The data is collected from S&P 500 with a time-span of 5 years. The independent variables are standardized and all rows containing NA are removed. asreg works just fine without newey, but when newey is included I am unable to run it.

encode ticker, gen(ticker1)
gen date1 = date(dates,"YMD")
xtset ticker1 date1

# this code works

asreg abnormal_returns lagabs_abnormal_returns lagabnormal_turnover ///
lagasvi laglog_market_cap laglog_market_cap_asvi lagadvsales lagnum_analysts, fmb 

#this code does not work

asreg abnormal_returns lagabs_abnormal_returns lagabnormal_turnover ///
lagasvi laglog_market_cap laglog_market_cap_asvi lagadvsales lagnum_analysts, fmb newey(8)

I get the following error:

no observations

stata():  3598  Stata returned error
                  FMB3():     -  function returned error
                 :     -  function returned error

Any help would be greatly appreciated!

    Attaullah Shah

    June 9, 2019at 12:44 pm

    Jon
    To debug the issue, I would need the following
    1. A sample of your data that generates the said error
    2. The asreg full command that you have used

    Can you please share the above with my dropbox email attashah15@hotmail.com or simply email these.

    Attaullah Shah

    June 9, 2019at 5:35 pm

    Jon
    Thanks for sending me your dataset. Turns out the problem is not with asreg, it is with your date variable. It has a significant number of gaps which the newey() option cannot handle. In other words, you are using the lag length of 8 with the newey() option, however, the gaps in your date variable are larger than 8 units and hence you get the error of no observations.

Shaika

June 29, 2019at 6:24 pm

Hi Sir,
Can we not use time series regression first and then cross-sectional in step two to avoid cross-sectional invariance of fama-french factor?
If we can, how can we use asreg for it?

    Attaullah Shah

    June 29, 2019at 6:47 pm

    Shaika
    It’s a question of theory. Does your theory suggest that? You have to dig deep and read the literature of the relevant field. If your literature allows that, then asreg can very easily implement that. The reason I am not showing the command to do that in asreg here is the potential misuse. Readers might not read the full story and quickly jump to do what you are asking for.

Shaika

June 30, 2019at 2:53 pm

Hi Sir,
Thanks for your reply. I saw some of the literature reports regression coefficients of Fama-French factor with Fama-Macbeth procedure. Regressing time series first would be the only option to avoid cross sectional invariance in this case. I tried to alter the xtset command and was able to get the results. Is this the way of doing it?
Thanks

Attaullah Shah

June 30, 2019at 3:53 pm

Shaika
This is against the spirit of Fama and MacBeth (1973). You might be missing some important steps of the papers you are referring to. Can you give full references to those papers here and copy paste the relevant text from them?

Gabriel

July 3, 2019at 2:49 pm

Hello Sir,
Thank you for the detailed and understandable explanation.
Personally, I am testing the Arbitrage Pricing Theory model using the Fama Macbeth procedure. However, my data is monthly for 10 companies and 5 independent variables.

My question is, when I do the fmb procedure, the coefficients that I get as the final result, how do I know/get for each company/dependent variable?

    Attaullah Shah

    July 3, 2019at 3:53 pm

    Gabriel
    You have asked how to get the individual coefficients of the independent variable for each company in Fama and MacBeth (1973) procedure? Well I would refer you to the start of this blog page. It mentions

    The Fama-McBeth (1973) regression is a two-step procedure . The first step involves estimation of N cross-sectional regressions and the second step involves T time-series averages of the coefficients of the N-cross-sectional regressions

    So the final step would just show the averages of the coefficients estimated in the first step. The first is to estimate as many cross-sectional regressions as the time periods. In other words, there are no company-specific coefficients in the final step. If you want to report the first stage results, then just add first to the fmb option as shown in the blog above.
    If you cannot still figure it out, then you can consider our paid help.

Patrick Larsen

July 19, 2019at 5:21 pm

Hi Sir,
I have been using the fmb-procedure during my dissertation and it has been working like a charm!
I produce consistent estimates and correct the time-series dependence with newey-west errors.

I run the regression in order to control for heterogeneity within mutual funds, and I wish to study the residuals over time in order to study price dispersion. Is it possible to receive cross-sectional residuals for each firm with this method? I basically wish to study whether high-cost funds have consistently been high-cost funds over the period. Method was inspired by:

Lach (2002) – Existence and Persistence of Price Dispersion: an Empirical Analysis
Michael Cooper, Michael Halling and Wenhao Yang – The Mutual Fund Fee Puzzle

When i try to predict residuals, i get the “option residuals not allowed”. I realize that the procedure theoretically doesn’t include specific companies and basically pull a random sample, but I have a rather consistent, yet unbalanced, panel.

Best regards

Patrick

    Attaullah Shah

    July 20, 2019at 12:14 am

    Pattrick
    Thanks for the feedback and asking about the possibility of generating residuals with FMB. As you have mentioned yourself, this option is not yet available and would a sufficient amount of time. I do not patrons who would support in adding further features to asreg. If you are interested, you can drop me an email at attaullah.shah@imsciences.edu.pk

Juan Meng

September 13, 2019at 6:52 pm

dear sir,
I have several questions about my regression in using Fama MacBeth regression.
first, my data is quarterly data. Will it impact my result? I mean the result will not as good as monthly data?
second, how about the ” xtfmb ” command? I get the same result as using “asreg”. but, how can I choose the lag when using “xtfmb”?
finally, in my data, T=42. however when I add zfc variable, it has some missing value, the results are as follows. is it OK? moreover, the R2 is not so good. is it OK?

      +----------------------------------------------------------------------------------------------------------+
      | _TimeVar      _obs       _R2    _adjR2   _b_zfc_w   _b_lnm~w   _b_lnb~w   _b_mom~w   _b_roa_w      _Cons |
      |----------------------------------------------------------------------------------------------------------|
      |        1       605   .334603   .330167   -1.18814   -.194754    .059856   -.176274     .00114    -1.5413 |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |        2       478   .285462   .279419   -2.31391    .114493    .033317   -.140444   -.000368   -.820059 |
      |        3       403   .096782   .087704    2.17037     .17927    -.01388   -.026993    .000588    .295026 |
      |        4       374   .379845   .373122     .64928    .512456   -.012888    .047207    .004885    .390056 |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |        5       395   .353318   .346685   -.391238    .360429    .023849   -.029407   -.000197   -.536491 |
      |        6       414   .303499   .296687    1.71153    .324702     .02116   -.045892     .00117   -.509786 |
      |        7       436   .397745   .392155    .929817    .467195    .010983   -.046324    .003655   -.208042 |
      |        8       463   .265287   .258871   -.362094    .286758   -.012448   -.057744     .00127    .240907 |
      |        .         .         .         .          .          .          .          .          .          . |
      |        9       488   .262314   .256205   -4.95519    .326975    .009172   -.069185   -.003059   -.250243 |
      |       10       520   .126417   .119632    .548104    .075897     .03785   -.078839    .002508   -.744467 |
      |        .         .         .         .          .          .          .          .          .          . |
      |       11       516   .208584   .202389   -1.78267    .277911    .014733   -.041569    .000448   -.317419 |
      |       12       523   .175439   .169071   -.190562    .298216    .010983   -.028738       .001    -.25795 |
      |       13       539   .322572   .317498   -2.42635    .420049    .005782   -.058516   -.000407   -.133489 |
      |       14       559   .331891   .327067   -.416547    .445676    .000097   -.047734    .000216   -.062654 |
      |       15       575   .390212   .385932   -2.04225    .460222     .03677    -.06749   -.000523   -.850231 |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |       16       552   .158852   .152701   -.017136    .275926    .005631   -.027023    .001491   -.115213 |
      |       17       566   .313222   .308325    1.49961     .41901    .033537   -.040457    .000643   -.800124 |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |       18       564   .289128   .284042   -1.71933    .288669    .013392   -.080446    .000756   -.305604 |
      |        .         .         .         .          .          .          .          .          .          . |
      |        .         .         .         .          .          .          .          .          .          . |
      |       19       571   .206877   .201272    .458813    .301066    .014665   -.015946       .001   -.314125 |
      |       20       589   .282247   .277331    .930542    .377147    .004653   -.076876    .001618   -.134379 |
      |        .         .         .         .          .          .          .          .          .          . |
      |       21       579   .289099   .284145    .166952    .272769    .037625    -.10305    .003514   -.923688 |
      |       22       612   .220619   .215483    1.34813    .389509   -.023238    .028232    -.00033    .561664 |
      |       23       615   .294692   .290067    .508339    .371758    .018569   -.041417    .002225   -.451321 |
      |       24       609   .211601    .20638    .517619    .348477    .002961   -.015103    .001224   -.088599 |
      |       25       591   .226542   .221262    .714496    .360819    .012367   -.023309    .001989   -.270746 |
      |       26       594   .299747   .294991   -.490053    .463732    .012137    .013863     .00108   -.229015 |
      |        .         .         .         .          .          .          .          .          .          . |
      |----------------------------------------------------------------------------------------------------------|
 Mean |     13.5   528.077   .270254   .264562   -.236225    .316322    .013755   -.048057    .001059   -.322204 |
      +----------------------------------------------------------------------------------------------------------+


Fama-MacBeth (1973) Two-Step procedure           Number of obs     =     18505
                                                 Num. time periods =        42
                                                 F(  5,    41)     =    148.86
                                                 Prob > F          =    0.0000
                                                 avg. R-squared    =    0.2772
                                                 Adj. R-squared    =    0.2688
------------------------------------------------------------------------------
             |            Fama-MacBeth
       rrq_w |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       roa_w |  -.2628664   .2243257    -1.17   0.248    -.7159013    .1901685
  momentum_w |   .3249877   .0208557    15.58   0.000     .2828688    .3671067
      lnme_w |   .0181009   .0032258     5.61   0.000     .0115863    .0246155
      lnbm_w |  -.0418565   .0063846    -6.56   0.000    -.0547505   -.0289625
       zfc_w |   .0009719   .0002437     3.99   0.000     .0004797    .0014641
       _cons |  -.4273105   .0760894    -5.62   0.000    -.5809763   -.2736448
------------------------------------------------------------------------------

    Attaullah Shah

    September 17, 2019at 8:02 am

    Juan Meng
    Statistically speaking, there is a general agreement on “the more, the merrier”, and this is the case with the monthly data as compared to quarterly data.

    (2) Yes, xtfmb and asreg produce exactly the same result, the only difference lies in the calculation time. asreg is much faster, and the difference in calculation time balloons as we use more data.

    (3) Usually, lower r-squared is an indication of omitted variable bias. There is no standard to which a lower or higher value can be compared. You may read several papers on this topic in your domain of research and see how low is the r-squared of your model.

Leave a Reply

15 − eleven =