Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fama-Macbeth (1973) with a cross-sectional invariant variable

    Dear all,

    How do I properly run a Fama-Macbeth regression with a cross-sectional invariant variable?

    Apologize for attaching screenshot instead of proper tables — still have to learn how to do it.

    I have a panel of 53 firms (id) with 18 years of daily observations of:
    • Return (ret),
    • Five Fama and French (2015) factors (rmrf, smb, hml, rmw, cma)
    • Social media sentiment variable (sentiment, invariant across firms)
    Here is what I do:
    Code:
    * generating firmnumbers *
    encode id, gen(idd)
    drop id
    rename idd id
    
    * sorting as panel *
    xtset id date
    
    * generating beta variables *
    gen beta_rmrf=.
    gen beta_smb=.
    gen beta_hml=.
    gen beta_rmw=.
    gen beta_cma=.
    gen beta_sentiment=.
    
    * loop to calculate beta *
    forvalues i=1/53{
    quietly reg ret rmrf smb hml rmw cma sentiment if id==`i'
    replace beta_rmrf=_b[rmrf] if id==`i'
    replace beta_smb=_b[smb] if id==`i'
    replace beta_hml=_b[hml] if id==`i'
    replace beta_rmw=_b[rmw] if id==`i'
    replace beta_cma=_b[cma] if id==`i'
    replace beta_fear=_b[fear] if id==`i'
    replace beta_sent=_b[sentiment] if id==`i'
    }
    * Fama Mac Beth Regression *
    tfmb ret beta_rmrf beta_smb beta_hml beta_rmw beta_cma beta_sent
    Here are 24 first rows of my data:
    Click image for larger version

Name:	Screen Shot 2019-04-21 at 17.10.54.png
Views:	1
Size:	300.7 KB
ID:	1494371





    Here is the summary of my variables (apologize for the screenshot):
    Click image for larger version

Name:	Screen Shot 2019-04-21 at 17.13.04.png
Views:	1
Size:	77.2 KB
ID:	1494372


    I realized that something is not right about my approach when I tried to run a Fama-Macbeth (1973) regression using areg commandwith fmb option, and it simply omitted my sentiment variable.

    Thank you!
    Last edited by Christian Backross; 21 Apr 2019, 09:35.

  • #2
    I tried to run a Fama-Macbeth (1973) regression using areg commandwith fmb option
    I think you mean the asreg command, a user-written command created by Attaullah Shah available through SSC. The areg command does not include the fmb option.

    If you read the output of help asreg you will see a link to the author's web page. Following that link leads eventually to a page on using asreg for FMB regression on which we see

    Since the FMB regression is a cross-sectional regression, estimated in each time period, therefore, the variables need to vary across entities.
    I believe that means your social media sentiment cannot be used in FMB regression.

    Comment


    • #3
      asreg has an option fmb that is used for estimating the Fama and MacBeth (1973) methodology.
      Code:
      ssc install asreg
      help asreg
      If a variable does not have cross-sectional variations, it will be dropped. If the sentiment variable in your dataset has the same value for different companies in a given period, then it does not vary cross-sectionally.
      Regards
      --------------------------------------------------
      Attaullah Shah, PhD.
      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
      FinTechProfessor.com
      https://asdocx.com
      Check out my asdoc program, which sends outputs to MS Word.
      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

      Comment


      • #4
        Originally posted by Attaullah Shah View Post
        asreg has an option fmb that is used for estimating the Fama and MacBeth (1973) methodology.
        Code:
        ssc install asreg
        help asreg
        If a variable does not have cross-sectional variations, it will be dropped. If the sentiment variable in your dataset has the same value for different companies in a given period, then it does not vary cross-sectionally.
        Correct, I was trying asreg and not areg.

        Ok, I understand that I cannot use asreg command, as it will drop my sentiment variable (since it is invariant across firms).

        But is the following method still valid?:
        Code:
        * generating firmnumbers *
        encode id, gen(idd)
        drop id
        rename idd id
        
        * sorting as panel *
        xtset id date
        
        * generating beta variables *
        gen beta_rmrf=.
        gen beta_smb=.
        gen beta_hml=.
        gen beta_rmw=.
        gen beta_cma=.
        gen beta_fear=.
        gen beta_stress=.
        
        * loop to calculate beta *
        forvalues i=1/53{
        quietly reg logret rmrf smb hml rmw cma fear stress if id==`i'
        replace beta_rmrf=_b[rmrf] if id==`i'
        replace beta_smb=_b[smb] if id==`i'
        replace beta_hml=_b[hml] if id==`i'
        replace beta_rmw=_b[rmw] if id==`i'
        replace beta_cma=_b[cma] if id==`i'
        replace beta_sent=_b[sentiment] if id==`i'
        }
        
        * Fama Mac Beth Regression *
        
        xtfmb logret beta_rmrf beta_smb beta_hml beta_rmw beta_cma beta_sent
        In other words, can I still use my cross-sectional invariant variable for a FMB (1973) regression?

        Side note: I was looking for an alternative to xtfmb command in stata because of its low calculation speed. Are there any other alternatives to xtfmb which will not drop my cross-sectional invariant variables?

        Thank you!

        Comment


        • #5
          First of all, both asreg and xtfmb are similar and produce the same results, with the only difference that asreg is several times faster. So whether you use xtfmb or asreg, you should get exactly the same result.

          Second, I have not completely understood what you want to do. Here is what I understood from your post. In the first part of your code, you seem to estimate a regression for each company in a loop. There, it seems you have 53 companies, correct? Is that is correct, then you do not need a loop for such regressions. asreg can do that in one line of code with blinking speed.

          Code:
          bys id: asreg logret rmrf smb hml rmw cma fear stress
          And the FMB regression
          Code:
          asreg logret beta_rmrf beta_smb beta_hml beta_rmw beta_cma beta_sent, fmb
          And finally, you asked that
          Are there any other alternatives to xtfmb which will not drop my cross-sectional invariant variables?
          Whatwever method you find for Fama and MacBeth regressions will drop your panel-invariant variable.
          Regards
          --------------------------------------------------
          Attaullah Shah, PhD.
          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
          FinTechProfessor.com
          https://asdocx.com
          Check out my asdoc program, which sends outputs to MS Word.
          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

          Comment


          • #6
            Originally posted by Attaullah Shah View Post

            And finally, you asked that Whatwever method you find for Fama and MacBeth regressions will drop your panel-invariant variable.
            Thank you for the explanation. However, Fama-French (2015) five factors are also firm-invariant, same as sentiment factor. Why does not asreg then drop those five factors too?

            Comment


            • #7
              Please post a sample data, your tsset command, and your Stata command using asreg. Only then I can tell what is going on there and why they are not dropped.
              Regards
              --------------------------------------------------
              Attaullah Shah, PhD.
              Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
              FinTechProfessor.com
              https://asdocx.com
              Check out my asdoc program, which sends outputs to MS Word.
              For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

              Comment


              • #8
                Originally posted by Attaullah Shah View Post
                Please post a sample data, your tsset command, and your Stata command using asreg. Only then I can tell what is going on there and why they are not dropped.
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input long(date id) double(logret rmrf hml smb rmw cma sentiment stress trust fear optimism)
                20000103  1           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  2           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  3           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  4           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  5           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  6           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  7           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  8           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103  9           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103 10           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103 11           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                20000103 12           .  -.71 -.84 -.14 -1.34 -.74  .005629 .059105 .000704 .011727 .004222
                Code:
                tsset id date
                asreg logret rmrf hml smb rmw cma sentiment, fmb
                
                ------------------------------------------------------------------------------
                             |            Fama-MacBeth
                      logret |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                        rmrf |   .0026199   .0000723    36.22   0.000     .0024781    .0027617
                         hml |   .0001742    .000025     6.96   0.000     .0001251    .0002232
                         smb |   .0001142   .0000203     5.61   0.000     .0000743    .0001541
                         rmw |  -.0000179   .0000132    -1.35   0.176    -.0000439    8.03e-06
                         cma |   .0000212   7.74e-06     2.74   0.006     6.05e-06    .0000364
                   sentiment |          0  (omitted)
                       _cons |   .0002179   .0000864     2.52   0.012     .0000485    .0003874
                ------------------------------------------------------------------------------

                Comment


                • #9
                  Christian Backross

                  I notice that you do not show us the output of the tsset command. It appears to me that you have not correctly constructed your date variable, and I suspect the output of xtset would have made that clear.

                  Stata's "date and time" variables are complicated and there is a lot to learn. If you have not already read the very detailed Chapter 24 (Working with dates and times) of the Stata User's Guide PDF, do so now. If you have, it's time for a refresher. After that, the help datetime documentation will usually be enough to point the way. You can't remember everything; even the most experienced users end up referring to the help datetime documentation or back to the manual for details. But at least you will get a good understanding of the basics and the underlying principles. An investment of time that will be amply repaid.

                  All Stata manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu.

                  The brief summary of the problem in your data is that Stata represents daily dates as the number of days from January 1 1960, and uses date formats to represent the Stata Internal Format (SIF) date as a Human Readable Form (HRF) date. The example code below demonstrates that Stata's internal representation of the date January 3 2000 is 14612. Your date value 20000103 corresponds to a SIF date over 54,000 years into the future. And between your date for the end of 2000 - 20001231 - and the beginning of 2001 - 20010101 - Stata would compute a 8870 day gap.

                  It is possible that these incongruous date values have caused problems. Certainly they should be corrected and your code rerun before trying to understand the inclusion and omission of particular variables.

                  Code:
                  . input long wrongdate
                  
                          wrongdate
                    1. 20000103
                    2. end
                  
                  . generate date = daily(strofreal(wrongdate,"%8.0f"),"YMD")
                  
                  . format date %td
                  
                  . generate unformatted_date = date
                  
                  . list, clean noobs abbreviate(20)
                  
                      wrongdate        date   unformatted_date  
                       20000103   03jan2000              14612

                  Comment


                  • #10
                    Originally posted by William Lisowski View Post
                    Christian Backross

                    I notice that you do not show us the output of the tsset command. It appears to me that you have not correctly constructed your date variable, and I suspect the output of xtset would have made that clear.
                    Thank you for the hint! Indeed, my data variable format was wrong. However, once I corrected it my results stayed the same (see below, sentiment variable is dropped).

                    Code:
                    xtset id date
                    
                           panel variable:  id (strongly balanced)
                            time variable:  date, 03jan2000 to 31dec2018, but with gaps
                                    delta:  1 day
                    
                    asreg logret rmrf hml smb rmw cma sentiment, fmb
                    
                    Fama-MacBeth (1973) Two-Step procedure           Number of obs     =    251198
                                                                     Num. time periods =      4740
                                                                     F(  6,  4739)     =    291.94
                                                                     Prob > F          =    0.0000
                                                                     avg. R-squared    =    0.0000
                    ------------------------------------------------------------------------------
                                 |            Fama-MacBeth
                          logret |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                            rmrf |   .0026199   .0000723    36.22   0.000     .0024781    .0027617
                             hml |   .0001742    .000025     6.96   0.000     .0001251    .0002232
                             smb |   .0001142   .0000203     5.61   0.000     .0000743    .0001541
                             rmw |  -.0000179   .0000132    -1.35   0.176    -.0000439    8.03e-06
                             cma |   .0000212   7.74e-06     2.74   0.006     6.05e-06    .0000364
                       sentiment |          0  (omitted)
                           _cons |   .0002179   .0000864     2.52   0.012     .0000485    .0003874
                    ------------------------------------------------------------------------------
                    Code:
                     summarize
                    
                        Variable |        Obs        Mean    Std. Dev.       Min        Max
                    -------------+---------------------------------------------------------
                            date |    253,287    18081.33    2002.252      14612      21549
                            year |    253,287    2009.003    5.474159       2000       2018
                             prc |    253,284    37.80264    28.53521   -7.34375   670.0625
                             vol |    253,280    1.29e+07    3.75e+07          0   1.90e+09
                             ret |    253,284    .0004433    .0269288   -.438095    .783333
                    -------------+---------------------------------------------------------
                          logret |    253,212    -.000144    .0294384  -1.372308   2.279307
                              st |    253,234    .0217376    .0141128   .0051012   .3122371
                        variance |    253,234    .0006717    .0020243    .000026    .097492
                       sentiment |    251,273   -.0473166    .1488078   -.470002    .392014
                        optimism |    251,273   -.0048559    .0228758   -.137394    .128534
                    -------------+---------------------------------------------------------
                           trust |    251,273    .0039366    .0050206   -.019494    .036595
                            fear |    251,273    .0113522    .0070639   -.003437    .056701
                          stress |    251,273    .0441509    .0134954    .012093    .165593
                            rmrf |    253,287     .021266    1.219459      -8.95      11.35
                             smb |    253,287    .0137602    .5970788      -4.33       4.49
                    -------------+---------------------------------------------------------
                             hml |    253,287    .0141348    .6626968      -4.22       4.83
                             rmw |    253,287    .0209144    .5166354      -2.92       4.39
                             cma |    253,287    .0144361     .426399      -5.93       2.41
                              rf |    253,287    .0063187    .0073847          0       .026
                              id |    253,287          27    15.29709          1         53

                    Code:
                    list date id logret rmrf smb hml rmw cma sentiment
                    
                            +----------------------------------------------------------------------------------+
                            |      date     id       logret    rmrf     smb     hml     rmw     cma   sentiment |
                            |----------------------------------------------------------------------------------|
                         1. | 03jan2000    AKS            .    -.71    -.14    -.84   -1.34    -.74    .005629 |
                         2. | 04jan2000    AKS   -.00704228   -4.06     .32    2.21     .31    1.46   -.113502 |
                         3. | 05jan2000    AKS    .05833558    -.09     .29     .13     .31     .99   -.263513 |
                         4. | 06jan2000    AKS    .06453852    -.73    -.15    1.37     .48    1.17   -.051759 |
                         5. | 07jan2000    AKS    .00312013    3.21    -.96   -1.24    -.75    -.94   -.080667 |
                            |----------------------------------------------------------------------------------|
                         6. | 10jan2000    AKS   -.03486882    1.76     .54    -1.5   -1.85    -.06    .248231 |
                         7. | 11jan2000    AKS   -.02946203   -1.71     .33     .92     .79    1.16    .137777 |
                         8. | 12jan2000    AKS   -.03035646    -.69    -.24      .9     .28     .89   -.146998 |
                         9. | 13jan2000    AKS    .00682596    1.59     .56   -1.31   -1.77   -1.05   -.028414 |
                        10. | 14jan2000    AKS    .01686381    1.15     .15    -.19    -.28    -.61    .139184 |
                            |----------------------------------------------------------------------------------|
                        11. | 18jan2000    AKS   -.00671143    -.25    2.32    -.47   -1.47    -.09   -.018526 |
                        12. | 19jan2000    AKS    .01005034     .44     .73    -.51      -1     .52   -.068363 |
                    Last edited by Christian Backross; 28 Apr 2019, 13:31.

                    Comment


                    • #11
                      The small sample you have posted does not tell me much. Can you please share the full data set with [email protected] using Dropbox. I shall look into it.
                      Regards
                      --------------------------------------------------
                      Attaullah Shah, PhD.
                      Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                      FinTechProfessor.com
                      https://asdocx.com
                      Check out my asdoc program, which sends outputs to MS Word.
                      For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                      Comment


                      • #12
                        Originally posted by Attaullah Shah View Post
                        The small sample you have posted does not tell me much. Can you please share the full data set with [email protected] using Dropbox. I shall look into it.
                        Done, thank you!

                        Comment


                        • #13
                          Please share Stata format file, not Excel file and also the Stata codes that you have been using.
                          Regards
                          --------------------------------------------------
                          Attaullah Shah, PhD.
                          Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                          FinTechProfessor.com
                          https://asdocx.com
                          Check out my asdoc program, which sends outputs to MS Word.
                          For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                          Comment


                          • #14
                            Originally posted by Attaullah Shah View Post
                            Please share Stata format file, not Excel file and also the Stata codes that you have been using.
                            Done!

                            Comment


                            • #15
                              Originally posted by Attaullah Shah View Post
                              Please share Stata format file, not Excel file and also the Stata codes that you have been using.
                              Do you think the problem is in the data?

                              Comment

                              Working...
                              X