Announcement

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

  • Fama&MacBeth: xtfmb function. Time-fixed effects

    Hello statalisters,

    My case is that of an unbalanced panel data composed by 25,714 companies ("cusip_id") and 528 months of data for each. I want to run the Fama and MacBeth procedure using the function xtfmb in which 528 cross-sectional regressions are performed and the coefficients then averaged across the time series. My command looks as follows:

    Code:
    xtfmb e_ret b s h r c w
    Where "e_ ret" are excess returns and "b, s, h, r, c, w" are factor loadings that I want to regress the former upon.

    Firstly, I suspect for the characteristics of the dataset that I should be correcting for fixed time effects as there are events in particular years that affect all companies across the board. The puzzle is that the function "xtfmb" does not allow for this and so I need to find a way around. Does anything come to mind?


    Secondly, I also want to correct my SE for autocorrelation and heteroskedasticity using the Newey-West Standard Errors, which the function "xtfmb" allow for by adding lags to the command:

    Code:
    xtfmb e_ret b s h r c w, lag(#)
    However, I do not know exactly what should be the appropiate number of lags. I have experienced that the more lags I include the more significant some coefficient become to the point of becoming highly significant so this is an important determinant for my results. Could you also help me on this?


    Thirdly, in using the function "xtfm" I have to declare beforehand that my panel data is such. Usually I would do so with the command "xtset cusip_id date"; however, in the help xtfmb the authors mention, "You must tsset your data before using xtfmb., thus should I be using "tsset cusip_id date" instead? And, that is really matter whether I use one or the other with a panel data?


    And lastly, since the panel data is fairly large, this function takes about 10 minutes to yield results. Apart from improving my computing power and dropping those variables that are not essential, do you have any other advice to speed up the process?



    To provide you with some backdrop here is a sample of my pane data:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double date long cusip_id float(e_ret b s h r c w)
    413 1 -6.432449 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    414 1      -.28 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    415 1  30.06478 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    416 1 1.2966667 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    417 1 1.2593442 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    418 1  6.081613 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    419 1 22.287273 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    420 1 4.5182714 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    421 1 1.9529412 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    422 1 13.333103 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    423 1  1.580202 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    424 1 4.4104953 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    425 1 10.850755 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    426 1  6.329661 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    427 1  7.863334 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    428 1 10.559011 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    429 1 16.361683 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    430 1 14.834237 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    431 1 28.921766 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    432 1   8.66091 1.5933827 4.1983247 -4.4861035 5.903217 .9038961 .9595598
    end
    format %tm date
    label values cusip_id cusip_id
    label def cusip_id 1 "00077R10", modify

    Fama and MacBeth procedure in Stata


    Thank you for your attention.
    Last edited by Roberto Iglesia; 11 Apr 2019, 06:51.

  • #2

    1. FMB regressions are cross-sectional regressions estimated in each timer period, therefore, fixed effects are hard to account for in this setting

    2. I am not sure about this

    3. Yes, the xtset declaration is a must for Fama and Macbeth regressions

    4. I can suggest asreg with fmb option. asreg is blinking fast. asreg can be downloaded from SSC.

    Code:
    ssc install asreg
    
    help asreg
    
    *Fama and McBeth Regression - using Newey-West errors
     
    webuse grunfeld, clear
     
    asreg invest mvalue kstock, fmb newey(1)
    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


    • #3
      Thank you Attaullah for your help. I

      will set aside my quest to account for time fixed effects in this type of regression but I am still puzzled about the appropiate number of lags I should include. Some people say T/10 as a thumb rule, others claim T^(1/4), but the results are wide different from one another. Also, I am not sure about how many lags is legitimate to include. Will the significance of my results be less valid the more lags I include?

      Comment


      • #4
        Hi Attaullah,

        I am new to stata and I have a panel dataset of a list of companies (c_id) over 36 years (year), where I would like to run a Fama Macbeth regression for each industry (ffic) and capture both the first and second stage coefficients.

        I am currently using the following code:

        bys year ffic: asreg lnp lnbvps lnabsnips nii lev, fmb save(first) min(10)

        Example generated by -dataex-. For more info, type help dataex
        clear
        input int(c_id year) float(lnp lnbvps) byte ffic float(lnabsnips lev) byte nii
        65 1985 .12469243 -.4034671 1 7.735225 .3670235 0
        229 1985 1.312917 .15956455 1 8.663819 .450534 0
        283 1985 1.9363792 1.1339794 1 8.360432 .07366804 0
        244 1985 1.528423 2.582336 1 7.366826 0 0
        277 1985 -.20850126 -.6217572 1 8.618151 .3933252 0
        269 1985 1.6387444 .8595087 1 8.334264 .355951 0
        22 1985 . . 1 . . .
        427 1985 . . 1 . . .
        302 1985 1.609438 1.595542 1 7.869625 .12512629 0
        299 1985 -.3634119 -.6792442 1 8.298982 .1728538 0
        260 1985 .8766348 -.11541088 1 7.511353 .4764272 0
        241 1985 . .3249778 1 8.427543 .38490635 0
        458 1985 . . 1 . . .
        384 1985 . . 1 . . .
        192 1985 -.1598167 .5031966 1 9.243596 .625918 0
        440 1985 . . 1 . . .
        231 1985 .9474793 -.12556319 1 7.406063 .46480125 1
        439 1985 -5.713833 . 1 . . .
        184 1985 .5463279 -.7298112 1 8.616334 .37680635 0
        333 1985 1.0893697 .4965239 1 7.922769 .3824816 0
        45 1985 . . 1 . . .
        204 1985 1.4733433 1.0086876 1 8.720251 .21970186 0
        300 1985 1.2613546 .9439059 1 7.437798 .24375373 0
        340 1985 . .3825376 1 . .13844107 0
        489 1985 1.7917595 .6491953 1 7.982391 .00645484 0
        205 1985 1.456683 .660624 1 8.255841 .14131564 0
        511 1985 . . 1 . . .
        201 1985 2.590167 1.3457328 1 7.548796 .04253354 0
        161 1985 .6207915 .1079571 1 8.413789 .23123562 0
        484 1985 . . 1 . . .
        439 1986 -6.214608 . 1 . . .
        45 1986 . . 1 . . .
        484 1986 . . 1 . . .
        161 1986 1.3139656 .4219944 1 7.640019 .4552488 0
        302 1986 1.8601967 1.6930435 1 8.0985985 .05719673 0
        244 1986 1.6532443 2.6179066 1 7.426266 0 0
        440 1986 . . 1 . . .
        427 1986 . . 1 . . .
        201 1986 2.5122056 1.5314764 1 7.750198 .024217043 0
        231 1986 1.3668567 -.018163977 1 8.317918 .4096021 0
        260 1986 1.6945875 .20294087 1 7.074674 .5187814 0
        205 1986 1.827577 .7021069 1 8.351529 .23142685 0
        22 1986 . . 1 . . .
        184 1986 .8556061 -.5603661 1 8.873896 .4004432 0
        489 1986 1.918759 .7518877 1 8.024458 .05929908 0
        458 1986 . . 1 . . .
        65 1986 .29252034 -.3481401 1 7.798533 .3622951 0
        192 1986 .3301666 .6830968 1 8.730985 .55001193 0
        511 1986 . . 1 . . .
        204 1986 2.025091 1.113501 1 8.146561 .22672145 0
        333 1986 1.5818406 .597737 1 8.061876 .3860841 0
        283 1986 2.3965216 1.2334346 1 7.66886 .06129952 0
        269 1986 1.7346952 1.12363 1 8.323015 .2344731 0
        340 1986 . -.4292456 1 . .53273153 0
        299 1986 -.03988492 -.59239733 1 7.617754 .15920086 0
        277 1986 .22330357 -.4992265 1 8.733642 .3403396 0
        300 1986 1.3548037 1.0581374 1 7.717619 .21925353 0
        229 1986 1.3825874 .27611542 1 8.530773 .5818577 0
        384 1986 . . 1 . . .
        241 1986 . .597737 1 7.857607 .3079116 0
        260 1987 1.9033456 .39136615 1 6.96545 .4461053 0
        229 1987 1.5941212 .4737466 1 7.717369 .56248146 0
        161 1987 1.5139177 .5900064 1 7.886054 .3570949 0
        384 1987 . . 1 . . .
        201 1987 2.674045 1.7606127 1 7.968718 .0510287 0
        427 1987 . . 1 . . .
        205 1987 1.822531 .8359479 1 7.411761 .3076474 0
        231 1987 1.6738577 .16466664 1 7.830996 .3434607 0
        22 1987 . . 1 . . .
        302 1987 2.125251 .2151114 1 8.507543 .8484178 0
        439 1987 -7.26443 . 1 . . .
        489 1987 1.8149225 .7055697 1 8.089845 .1827708 0
        269 1987 1.2892327 1.2745245 1 6.82002 .24003898 0
        299 1987 .19786672 -.5058381 1 7.779592 .25108036 0
        300 1987 1.5448568 1.205372 1 7.392568 .2208588 0
        45 1987 . . 1 . . .
        244 1987 1.257921 2.645962 1 7.224774 0 0
        65 1987 .0752002 -.28634965 1 7.841963 .4347559 0
        184 1987 .8325613 -.614336 1 7.774648 .456007 0
        484 1987 . . 1 . . .
        283 1987 2.472294 1.3775058 1 7.784752 .05825795 0
        192 1987 .51766217 .876718 1 8.954689 .4831452 0
        340 1987 .4147552 -.55164766 1 8.117563 .6097036 1
        511 1987 . . 1 . . .
        440 1987 . . 1 . . .
        241 1987 . .8977193 1 8.072174 .2672393 0
        277 1987 .4445576 -.3827257 1 8.364572 .27479997 0
        458 1987 . . 1 . . .
        204 1987 2.063782 1.2169877 1 8.245233 .2143633 0
        333 1987 1.536394 .2303177 1 7.714284 .3793491 0
        277 1988 .4809436 -.4780358 1 8.688847 .30229175 0
        184 1988 1.0228825 -.6236211 1 7.931227 .41094396 0
        440 1988 . . 1 . . .
        427 1988 . . 1 . . .
        161 1988 1.293987 .6956441 1 7.84623 .2289212 0
        302 1988 1.5712167 .5364934 1 7.734842 .79919 0
        241 1988 2.623305 1.1039314 1 8.26424 .3244363 0
        45 1988 . . 1 . . .
        333 1988 1.612493 .4953058 1 7.593753 .3864242 0
        231 1988 1.5706347 .27307594 1 8.1093645 .5306167 0
        end
        [/CODE]

        However, while I have 12 industries in (ffic), stata will only generate 1 set of results and first stage coefficients:

        Example generated by -dataex-. For more info, type help dataex
        clear
        input double(_b_lnbvps _b_lnabsnips _b_nii _b_lev) float(_Cons _R2 _adjR2 _TimeVar _obs)
        .7228067839119938 .08480428292345188 -.18537979921575243 -.7206596139690982 .2733085 .7486453 .7437168 1985 209
        .7389965662884772 .09160037387036013 -.5248942329549582 -.6928795169167046 .3438795 .787138 .7830835 1986 215
        .6802023207473535 .1713481315857628 -.11801550092169144 -.5090559820389906 -.3713796 .7358001 .7309746 1987 224
        .711229163184349 .146591899852325 -.5188302057366618 -.25276427213056696 -.2756399 .7924435 .7888954 1988 239
        .7177863929690623 .09907923876833813 -.33596460999839284 -.2706761481718907 .24603197 .7395509 .7352281 1989 246
        .6645985037742603 .14092858414461418 -.39217836840114817 -.28705158897163763 -.08756484 .6783146 .6731262 1990 253
        .6664868590551272 .16136246045243574 -.24910724111207116 -.3699889645398198 .06344793 .6641291 .6588812 1991 261
        .6554813858754094 .10081498505106623 -.3741974103044028 -.15634399794239773 .59199554 .6630132 .6580757 1992 278
        .6536397554680771 .07541717830968331 -.3309556100403199 -.1944175235538692 .8629785 .6910295 .6866624 1993 288
        .6565243682416821 -.016265148571829258 -.34223479628609965 -.19497958481689892 1.4525273 .6677353 .6633198 1994 306
        .6526562248284487 -.023118173103828354 -.14679365723416993 -.23237071380147611 1.6928903 .6281188 .6233203 1995 315
        .646142317551933 .005305277247490636 -.15643068484296307 .0108718754223176 1.480162 .6240382 .6194251 1996 331
        .6106361083170246 .12248016546438834 -.25915480700068727 .05715008779823538 .8434149 .6329077 .6284446 1997 334
        .5517842873989132 .13552886502048622 -.21347113589296995 .24011193562145183 .8041 .50896674 .5030861 1998 339
        .5174202933616383 .160906644371277 -.05313952183309212 -.1802951217817883 .8460352 .4000922 .3932164 1999 354
        .5961596459689176 .0833436007393793 -.24331490194483862 -.27080131818973463 1.4022104 .4483942 .4423822 2000 372
        .5686145054897567 .01878949994531709 -.22394053101956501 -.09003921100618165 1.8421296 .5047986 .4995024 2001 379
        .5258047507796346 .03775597942123454 -.5526107556010318 .09924583877999549 1.6147118 .4910983 .4857695 2002 387
        .5623276151831174 .08111031499039001 -.24046311181085045 .12368846142362111 1.3090757 .5807448 .5764226 2003 393
        .5158925411005786 .11202627994656211 -.24393118179958506 .17882335155371543 1.2627417 .597981 .5938683 2004 396
        .4861255093623136 .17428435156616473 -.05479721605607324 .1372619726926949 .9090772 .602916 .5989942 2005 410
        .44374002594855 .12117162966382722 -.2583498653780225 .4317395347635655 1.3840902 .56337476 .5591561 2006 419
        .42319529803089484 .16027163761172147 -.30617633141808653 .14518172763889758 1.2763335 .4982775 .49353305 2007 428
        .33316703663156155 .14262391192975343 -.5669655836890937 .10666330825402603 1.2753296 .37639445 .3706069 2008 436
        .40978964385198635 .14117261239564627 -.4559583074001772 .16144429061787946 1.215707 .4665431 .4615923 2009 436
        .3404473118904743 .25774786716532105 -.16918316763520025 .21403603691194206 .57071596 .4625135 .4575937 2010 442
        .2654357167407393 .3228080850101236 .08760944976517493 .1763350792699825 .2618812 .398099 .3926886 2011 450
        .27651634616175613 .24419063671370012 -.2572287164959235 .2970944767241974 .9392077 .380446 .3750113 2012 461
        .2656474994881537 .30571873819825157 .1340075026572194 .13853248550315556 .7354341 .4172144 .4121686 2013 467
        .19042715001479887 .3578587123573769 .3250406422030423 .24170163455453064 .6098991 .4081478 .4031 2014 474
        .1835470498855919 .3283954734884915 -.3326755225078273 .18325817508990383 .9223272 .3640601 .358716 2015 481
        .24444980556189416 .3679257754971772 -.1595055301417858 .1311015835031597 .51513875 .455558 .4510305 2016 486
        .21862006366625897 .30216038276585167 -.28470681499804584 .1243093254468306 1.2622753 .4254324 .4206839 2017 489
        .15165542912972674 .39686029711766224 .04994477310113865 -.05288640013194623 .6028605 .3792601 .3741406 2018 490
        .15176730398243699 .4463466207355893 -.2564276853713565 .11863473356111598 .3146791 .455317 .45084324 2019 492
        .2260884311459641 .3309343264887872 -.7844902179765141 .08708345115297789 1.2008368 .40906975 .404226 2020 493
        end
        [/CODE]


        What I am trying to do is to get 12 sets of coefficients for each year, 1 for each industry each year which I can then use in the next stage of my analysis.

        Thanks for any assistance in advance.

        Ammar.
        Last edited by Ammar Azhari Ahmed; 09 Jun 2021, 18:18.

        Comment

        Working...
        X