Announcement

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

  • Compare coefficients with xtreg i.year and fe

    Hello,

    I have two models:

    Model A: Y = α1 + β1X1 + Σθ∙C + firm-fixed effect + year-fixed effect

    Model B: Y = α1 + β2X2 + Σθ∙C + firm-fixed effect + year-fixed effect

    Where Σθ∙C is list of controlling variables and are the same for both model A & B

    I want to compare the coefficients of β1 and β2

    I search some related threads. The closest one is here: https://www.stata.com/statalist/arch.../msg00275.html

    If there is no time effect in my model, everything works fine as the example in the link. However, there is time fixed effect and I do not know how to deal with it


    Code of each model:

    HTML Code:
    xtreg y x control1 control2 i.year, fe
    Thank you
    Phan

  • #2
    Phan:
    you can use -regress- to estimate the two -fe- regression models and then compare the coefficients of interest via -suest- (with clustered standard errors) and -test-:
    Code:
    . use "https://www.stata-press.com/data/r17/nlswork.dta"
    (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
    
    . reg ln_wage age i.year idcode if idcode<=3
    
          Source |       SS           df       MS      Number of obs   =        39
    -------------+----------------------------------   F(16, 22)       =      2.88
           Model |  3.50459831        16  .219037395   Prob > F        =    0.0112
        Residual |  1.67114064        22  .075960938   R-squared       =    0.6771
    -------------+----------------------------------   Adj R-squared   =    0.4423
           Total |  5.17573896        38  .136203657   Root MSE        =    .27561
    
    ------------------------------------------------------------------------------
         ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             age |   .0553783    .033142     1.67   0.109     -.013354    .1241106
                 |
            year |
             69  |   .1535887   .3911781     0.39   0.698    -.6576649    .9648423
             70  |  -.3834514   .3486051    -1.10   0.283    -1.106414    .3395114
             71  |  -.5225361   .3299476    -1.58   0.128    -1.206805    .1617332
             72  |  -.4222206   .3382339    -1.25   0.225    -1.123675    .2792336
             73  |  -.3029477   .3494793    -0.87   0.395    -1.027723     .421828
             75  |   -.341031   .3797279    -0.90   0.379    -1.128538    .4464765
             77  |  -.4575209   .4183753    -1.09   0.286    -1.325178    .4101365
             78  |  -.3054729   .4401766    -0.69   0.495    -1.218343    .6073974
             80  |  -.3869355   .4876277    -0.79   0.436    -1.398214    .6243425
             82  |  -.5951095   .5353696    -1.11   0.278    -1.705398    .5151792
             83  |  -.5332353   .5659459    -0.94   0.356    -1.706935    .6404647
             85  |  -.5651818   .6215207    -0.91   0.373    -1.854137    .7237731
             87  |  -.7511611   .6790201    -1.11   0.281    -2.159363    .6570404
             88  |  -.8356305   .7280781    -1.15   0.263    -2.345572     .674311
                 |
          idcode |  -.3964822   .1145466    -3.46   0.002    -.6340374    -.158927
           _cons |   1.464686   .5364224     2.73   0.012     .3522144    2.577158
    ------------------------------------------------------------------------------
    
    . estimates store m1
    
    . reg ln_wage tenure i.year idcode if idcode<=3
    
          Source |       SS           df       MS      Number of obs   =        39
    -------------+----------------------------------   F(16, 22)       =      2.45
           Model |  3.31673371        16  .207295857   Prob > F        =    0.0259
        Residual |  1.85900525        22  .084500238   R-squared       =    0.6408
    -------------+----------------------------------   Adj R-squared   =    0.3796
           Total |  5.17573896        38  .136203657   Root MSE        =    .29069
    
    ------------------------------------------------------------------------------
         ln_wage | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          tenure |  -.0146763   .0274125    -0.54   0.598    -.0715264    .0421737
                 |
            year |
             69  |   .2138591   .4111982     0.52   0.608    -.6389138    1.066632
             70  |  -.2536062   .3623872    -0.70   0.491    -1.005151    .4979389
             71  |  -.3884103   .3432804    -1.13   0.270     -1.10033    .3235096
             72  |  -.2200786   .3469289    -0.63   0.532    -.9395651    .4994079
             73  |  -.0482811   .3459676    -0.14   0.890    -.7657741    .6692118
             75  |   .0121618   .3427575     0.04   0.972    -.6986738    .7229975
             77  |   .0325197   .3513701     0.09   0.927    -.6961773    .7612167
             78  |   .2427996   .3527081     0.69   0.498    -.4886722    .9742714
             80  |   .2994078   .3691807     0.81   0.426    -.4662262    1.065042
             82  |   .2145952   .4186849     0.51   0.613    -.6537041    1.082895
             83  |    .342888   .3883197     0.88   0.387    -.4624377    1.148214
             85  |   .4045756   .3740376     1.08   0.291     -.371131    1.180282
             87  |   .3000002   .3549622     0.85   0.407    -.4361463    1.036147
             88  |   .3261734   .3660395     0.89   0.383    -.4329461    1.085293
                 |
          idcode |  -.2155394   .0640443    -3.37   0.003    -.3483591   -.0827196
           _cons |   2.140179    .348447     6.14   0.000     1.417545    2.862814
    ------------------------------------------------------------------------------
    
    . estimates store m2
    
    . suest m1 m2, vce(cluster idcode)
    
    Simultaneous results for m1, m2                             Number of obs = 39
    
                                     (Std. err. adjusted for 3 clusters in idcode)
    ------------------------------------------------------------------------------
                 |               Robust
                 | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    m1_mean      |
             age |   .0553783   .0059185     9.36   0.000     .0437783    .0669782
                 |
            year |
             69  |   .1535887   .0059185    25.95   0.000     .1419888    .1651887
             70  |  -.3834514   .2104246    -1.82   0.068     -.795876    .0289732
             71  |  -.5225361   .3045608    -1.72   0.086    -1.119464    .0743921
             72  |  -.4222206   .1708272    -2.47   0.013    -.7570357   -.0874055
             73  |  -.3029477   .1033586    -2.93   0.003    -.5055268   -.1003686
             75  |   -.341031   .1557406    -2.19   0.029     -.646277   -.0357849
             77  |  -.4575209   .1527493    -3.00   0.003     -.756904   -.1581377
             78  |  -.3054729   .0954847    -3.20   0.001    -.4926194   -.1183264
             80  |  -.3869355   .0989688    -3.91   0.000    -.5809108   -.1929602
             82  |  -.5951095   .0827013    -7.20   0.000     -.757201    -.433018
             83  |  -.5332353   .0322579   -16.53   0.000    -.5964597   -.4700109
             85  |  -.5651818   .0576019    -9.81   0.000    -.6780795   -.4522842
             87  |  -.7511611   .0606426   -12.39   0.000    -.8700184   -.6323039
             88  |  -.8356305   .0217378   -38.44   0.000    -.8782359   -.7930251
                 |
          idcode |  -.3964822    .016855   -23.52   0.000    -.4295175    -.363447
           _cons |   1.464686   .0801744    18.27   0.000     1.307547    1.621825
    -------------+----------------------------------------------------------------
    m1_lnvar     |
           _cons |  -2.577536    .386569    -6.67   0.000    -3.335197   -1.819875
    -------------+----------------------------------------------------------------
    m2_mean      |
          tenure |  -.0146763   .0192884    -0.76   0.447     -.052481    .0231283
                 |
            year |
             69  |   .2138591   .0064295    33.26   0.000     .2012575    .2264606
             70  |  -.2536062    .206985    -1.23   0.220    -.6592893    .1520769
             71  |  -.3884103   .2925271    -1.33   0.184     -.961753    .1849323
             72  |  -.2200786   .1909001    -1.15   0.249    -.5942358    .1540786
             73  |  -.0482811   .1021194    -0.47   0.636    -.2484316    .1518693
             75  |   .0121618   .0918256     0.13   0.895     -.167813    .1921367
             77  |   .0325197   .0647791     0.50   0.616    -.0944449    .1594843
             78  |   .2427996   .1876228     1.29   0.196    -.1249344    .6105336
             80  |   .2994078   .2328391     1.29   0.198    -.1569484     .755764
             82  |   .2145952   .1322155     1.62   0.105    -.0445424    .4737328
             83  |    .342888   .1708185     2.01   0.045     .0080899    .6776861
             85  |   .4045756   .2270957     1.78   0.075    -.0405237     .849675
             87  |   .3000002   .2191341     1.37   0.171    -.1294947    .7294952
             88  |   .3261734   .1999817     1.63   0.103    -.0657834    .7181303
                 |
          idcode |  -.2155394    .023322    -9.24   0.000    -.2612497    -.169829
           _cons |   2.140179   .0699661    30.59   0.000     2.003048    2.277311
    -------------+----------------------------------------------------------------
    m2_lnvar     |
           _cons |  -2.471001   .3620112    -6.83   0.000     -3.18053   -1.761472
    ------------------------------------------------------------------------------
    
    . test [m1_mean]age=[m2_mean]tenure
    
     ( 1)  [m1_mean]age - [m2_mean]tenure = 0
    
               chi2(  1) =    7.77
             Prob > chi2 =    0.0053
    
    .
    Please note that you cannot invoke clustered standard errors when -regress- (as you should whenevener using OLS with a panel dataset) if you plan to go -suest-.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Carlo Lazzaro
      Thank you for your comment

      There is an issue I hope you can clarify.

      Issue 1: in your example, does?
      Code:
      reg ln_wage age i.year idcode
      equivalent to
      Code:
      xtreg ln_wage age i.year, fe
      They are inequivalent as the coefficients result in two codes are different. My equation is similar to the 2nd one:
      Code:
      xtreg ln_wage age i.year, fe
      The result:

      Code:
      . reg ln_wage age i.year idcode
      
            Source |       SS           df       MS      Number of obs   =    28,510
      -------------+----------------------------------   F(16, 28493)    =    218.73
             Model |  712.857066        16  44.5535666   Prob > F        =    0.0000
          Residual |  5803.83309    28,493  .203693296   R-squared       =    0.1094
      -------------+----------------------------------   Adj R-squared   =    0.1089
             Total |  6516.69015    28,509  .228583611   Root MSE        =    .45132
      
      ------------------------------------------------------------------------------
           ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               age |   .0149675   .0009086    16.47   0.000     .0131865    .0167484
                   |
              year |
               69  |   .0843118   .0177457     4.75   0.000     .0495294    .1190942
               70  |   .0538523    .016428     3.28   0.001     .0216525     .086052
               71  |   .0863211   .0161403     5.35   0.000     .0546854    .1179568
               72  |   .0993529    .016493     6.02   0.000     .0670259    .1316799
               73  |   .0971639   .0160726     6.05   0.000     .0656609    .1286669
               75  |   .0756475   .0161771     4.68   0.000     .0439395    .1073554
               77  |   .1267379   .0167237     7.58   0.000     .0939586    .1595172
               78  |   .1702232   .0173778     9.80   0.000     .1361619    .2042845
               80  |   .1516086    .018379     8.25   0.000     .1155849    .1876323
               82  |   .1183352   .0190047     6.23   0.000     .0810851    .1555853
               83  |   .1462736   .0196613     7.44   0.000     .1077365    .1848107
               85  |    .178119   .0206659     8.62   0.000     .1376128    .2186253
               87  |   .1552026    .021835     7.11   0.000     .1124048    .1980003
               88  |   .1744797   .0226471     7.70   0.000     .1300903    .2188692
                   |
            idcode |   -.000054   1.80e-06   -30.05   0.000    -.0000576   -.0000505
             _cons |   1.261359   .0229828    54.88   0.000     1.216312    1.306406
      ------------------------------------------------------------------------------
      
      . xtreg ln_wage age i.year, fe
      
      Fixed-effects (within) regression               Number of obs     =     28,510
      Group variable: idcode                          Number of groups  =      4,710
      
      R-sq:                                           Obs per group:
           within  = 0.1060                                         min =          1
           between = 0.0914                                         avg =        6.1
           overall = 0.0805                                         max =         15
      
                                                      F(15,23785)       =     188.00
      corr(u_i, Xb)  = 0.0467                         Prob > F          =     0.0000
      
      ------------------------------------------------------------------------------
           ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               age |   .0125992   .0102163     1.23   0.217    -.0074253    .0326238
                   |
              year |
               69  |   .0748621   .0159011     4.71   0.000      .043695    .1060292
               70  |   .0478697   .0235673     2.03   0.042     .0016763     .094063
               71  |   .0865577   .0327939     2.64   0.008     .0222795     .150836
               72  |   .0856757   .0424903     2.02   0.044     .0023919    .1689594
               73  |   .0880069    .052344     1.68   0.093    -.0145906    .1906044
               75  |   .0778607   .0720304     1.08   0.280    -.0633235    .2190449
               77  |    .108365   .0922272     1.17   0.240    -.0724063    .2891363
               78  |   .1309518   .1028143     1.27   0.203    -.0705707    .3324743
               80  |   .1142649    .122792     0.93   0.352    -.1264152     .354945
               82  |   .1090451   .1431112     0.76   0.446    -.1714619    .3895522
               83  |   .1211272   .1532018     0.79   0.429    -.1791581    .4214125
               85  |   .1465637   .1736146     0.84   0.399    -.1937321    .4868594
               87  |   .1382642   .1941163     0.71   0.476     -.242216    .5187445
               88  |   .1799741   .2079871     0.87   0.387    -.2276938     .587642
                   |
             _cons |   1.203731   .1952306     6.17   0.000     .8210667    1.586396
      -------------+----------------------------------------------------------------
           sigma_u |   .4058746
           sigma_e |  .30300411
               rho |  .64212421   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      F test that all u_i=0: F(4709, 23785) = 8.80                 Prob > F = 0.0000
      Issue 2: Also I know that there is a work around method by using OLS and `suest' by running
      HTML Code:
      reg yvar xvar i.year i.firm
      however, I have many firms, using this would result in: (i) exceed limit of variables allowed, (ii) take a very long time to run.

      Last edited by Truong Quoc Phan; 01 Jun 2022, 02:11.

      Comment


      • #4
        Truong:
        1) There was a typo in my previous code. Sorry for that. Correction follows:
        Code:
        reg ln_wage age i.year i.idcode
        2) how to tackle the issue in an effective and (more) efficinety way:
        Code:
        . use "https://www.stata-press.com/data/r17/nlswork.dta"
        . xtreg ln_wage tenure i.year , fe vce(cluster idcode)
        
        Fixed-effects (within) regression               Number of obs     =     28,101
        Group variable: idcode                          Number of groups  =      4,699
        
        R-squared:                                      Obs per group:
             Within  = 0.1328                                         min =          1
             Between = 0.1830                                         avg =        6.0
             Overall = 0.1428                                         max =         15
        
                                                        F(15,4698)        =     112.49
        corr(u_i, Xb) = 0.1302                          Prob > F          =     0.0000
        
                                     (Std. err. adjusted for 4,699 clusters in idcode)
        ------------------------------------------------------------------------------
                     |               Robust
             ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
              tenure |   .0210664   .0012238    17.21   0.000     .0186672    .0234656
                     |
                year |
                 69  |   .0834009   .0105041     7.94   0.000      .062808    .1039939
                 70  |   .0581181    .010931     5.32   0.000     .0366882    .0795481
                 71  |   .1039541   .0114729     9.06   0.000     .0814618    .1264463
                 72  |    .111102   .0123314     9.01   0.000     .0869266    .1352774
                 73  |   .1190714   .0124842     9.54   0.000     .0945965    .1435463
                 75  |    .125436   .0127029     9.87   0.000     .1005325    .1503396
                 77  |   .1726586   .0133431    12.94   0.000     .1464998    .1988175
                 78  |    .198183   .0140385    14.12   0.000     .1706611     .225705
                 80  |   .2041747   .0142586    14.32   0.000     .1762212    .2321282
                 82  |   .2078031   .0146046    14.23   0.000     .1791711     .236435
                 83  |   .2198642   .0155454    14.14   0.000      .189388    .2503405
                 85  |   .2606739   .0153396    16.99   0.000     .2306012    .2907466
                 87  |    .266248    .016293    16.34   0.000     .2343061      .29819
                 88  |   .3096376   .0180115    17.19   0.000     .2743266    .3449485
                     |
               _cons |   1.438391   .0103043   139.59   0.000      1.41819    1.458592
        -------------+----------------------------------------------------------------
             sigma_u |  .39153681
             sigma_e |   .2976287
                 rho |  .63377952   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        
        . local coef1=_b[tenure]
        
        . . xtreg ln_wage age i.year , fe vce(cluster idcode)
        
        Fixed-effects (within) regression               Number of obs     =     28,510
        Group variable: idcode                          Number of groups  =      4,710
        
        R-squared:                                      Obs per group:
             Within  = 0.1060                                         min =          1
             Between = 0.0914                                         avg =        6.1
             Overall = 0.0805                                         max =         15
        
                                                        F(15,4709)        =      69.49
        corr(u_i, Xb) = 0.0467                          Prob > F          =     0.0000
        
                                     (Std. err. adjusted for 4,710 clusters in idcode)
        ------------------------------------------------------------------------------
                     |               Robust
             ln_wage | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 age |   .0125992   .0123091     1.02   0.306    -.0115323    .0367308
                     |
                year |
                 69  |   .0748621   .0156425     4.79   0.000     .0441955    .1055287
                 70  |   .0478697   .0265729     1.80   0.072    -.0042256    .0999649
                 71  |   .0865577   .0385328     2.25   0.025     .0110155       .1621
                 72  |   .0856757   .0505004     1.70   0.090    -.0133288    .1846802
                 73  |   .0880069   .0626993     1.40   0.160    -.0349132    .2109269
                 75  |   .0778607   .0865126     0.90   0.368    -.0917446     .247466
                 77  |    .108365   .1111117     0.98   0.329    -.1094659    .3261959
                 78  |   .1309518   .1237306     1.06   0.290    -.1116181    .3735217
                 80  |   .1142649   .1480678     0.77   0.440    -.1760172    .4045471
                 82  |   .1090451   .1724619     0.63   0.527    -.2290608    .4471511
                 83  |   .1211272   .1846402     0.66   0.512    -.2408539    .4831083
                 85  |   .1465637   .2092454     0.70   0.484    -.2636552    .5567825
                 87  |   .1382642   .2341219     0.59   0.555    -.3207242    .5972527
                 88  |   .1799741   .2500607     0.72   0.472    -.3102618      .67021
                     |
               _cons |   1.203731    .235213     5.12   0.000     .7426037    1.664859
        -------------+----------------------------------------------------------------
             sigma_u |   .4058746
             sigma_e |  .30300411
                 rho |  .64212421   (fraction of variance due to u_i)
        ------------------------------------------------------------------------------
        
        . test  `coef1'=_b[age]
        
         ( 1)  - age = -.0210664
        
               F(  1,  4709) =    0.47
                    Prob > F =    0.4916
        
        .
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Carlo Lazzaro Thank you so much

          Comment

          Working...
          X