Announcement

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

  • Firm Fixed effects

    Dear Stata Users,

    I am working with a panel dataset and I need to add firm fixed effects in my regression models.

    I do not know how to calculate them. Usually, I adopt the following command to generate for example year fe:
    tab Year, gen(year), then I include them in the models. I do not think I can do the same with firms since I have thousands of id in the dataset.
    Is there an alternative approach to include firm fixed effects in the models?

    Thank you in advance for your support,
    Regards,
    N






  • #2
    In the Grunfeld dataset, the firm identifier is named "company". So if you xtset using the variable identifying firms and use xtreg with the -fe- option, it automatically includes firm fixed effects in the regression. No need to manually generate indicators. See

    Code:
    help xtreg
    Code:
    webuse grunfeld, clear
    xtset company
    xtreg invest mvalue kstock i.year, fe
    Res.:

    Code:
    . xtreg invest mvalue kstock i.year, fe
    
    Fixed-effects (within) regression               Number of obs     =        200
    Group variable: company                         Number of groups  =         10
    
    R-sq:                                           Obs per group:
         within  = 0.7985                                         min =         20
         between = 0.8143                                         avg =       20.0
         overall = 0.8068                                         max =         20
    
                                                    F(21,169)         =      31.90
    corr(u_i, Xb)  = -0.3250                        Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
          invest |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          mvalue |   .1177158   .0137513     8.56   0.000     .0905694    .1448623
          kstock |   .3579163    .022719    15.75   0.000     .3130667    .4027659
                 |
            year |
           1936  |  -19.19741   23.67586    -0.81   0.419    -65.93593    27.54112
           1937  |  -40.69001   24.69541    -1.65   0.101    -89.44122    8.061213
           1938  |   -39.2264   23.23594    -1.69   0.093    -85.09647    6.643667
           1939  |  -69.47029   23.65607    -2.94   0.004    -116.1698   -22.77083
           1940  |  -44.23507   23.80979    -1.86   0.065      -91.238     2.76785
           1941  |  -18.80446     23.694    -0.79   0.429     -65.5788    27.96987
           1942  |  -21.13979   23.38163    -0.90   0.367    -67.29748    25.01789
           1943  |  -42.97762   23.55287    -1.82   0.070    -89.47334    3.518104
           1944  |  -43.09876    23.6102    -1.83   0.070    -89.70766    3.510134
           1945  |  -55.68303   23.89561    -2.33   0.021    -102.8554   -8.510689
           1946  |  -31.16928   24.11598    -1.29   0.198    -78.77665    16.43809
           1947  |  -39.39223   23.78368    -1.66   0.100    -86.34361    7.559141
           1948  |  -43.71651   23.96965    -1.82   0.070    -91.03501    3.601991
           1949  |   -73.4951   24.18292    -3.04   0.003    -121.2346   -25.75559
           1950  |  -75.89611   24.34553    -3.12   0.002    -123.9566    -27.8356
           1951  |   -62.4809   24.86425    -2.51   0.013    -111.5654   -13.39637
           1952  |  -64.63233    25.3495    -2.55   0.012    -114.6748   -14.58987
           1953  |  -67.71796   26.61108    -2.54   0.012    -120.2509   -15.18501
           1954  |  -93.52622   27.10786    -3.45   0.001    -147.0399   -40.01257
                 |
           _cons |  -32.83631   18.87533    -1.74   0.084     -70.0981    4.425483
    -------------+----------------------------------------------------------------
         sigma_u |  91.798268
         sigma_e |  51.724523
             rho |  .75902159   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(9, 169) = 52.36                     Prob > F = 0.0000
    
    .

    Comment


    • #3
      Nicola:
      as as aside to Andrew's excellent reply, -xtset-ting your dataset with -panelid- only comes at the cost of making time-series related commands (such as lags and leads) unavailable:
      Code:
       webuse grunfeld, clear
      
      . xtset company
      
      Panel variable: company (balanced)
      
      . xtreg invest mvalue kstock i.year, fe
      
      Fixed-effects (within) regression               Number of obs     =        200
      Group variable: company                         Number of groups  =         10
      
      R-squared:                                      Obs per group:
           Within  = 0.7985                                         min =         20
           Between = 0.8143                                         avg =       20.0
           Overall = 0.8068                                         max =         20
      
                                                      F(21,169)         =      31.90
      corr(u_i, Xb) = -0.3250                         Prob > F          =     0.0000
      
      ------------------------------------------------------------------------------
            invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
            mvalue |   .1177158   .0137513     8.56   0.000     .0905694    .1448623
            kstock |   .3579163    .022719    15.75   0.000     .3130667    .4027659
                   |
              year |
             1936  |  -19.19741   23.67586    -0.81   0.419    -65.93593    27.54112
             1937  |  -40.69001   24.69541    -1.65   0.101    -89.44122    8.061213
             1938  |   -39.2264   23.23594    -1.69   0.093    -85.09647    6.643667
             1939  |  -69.47029   23.65607    -2.94   0.004    -116.1698   -22.77083
             1940  |  -44.23507   23.80979    -1.86   0.065      -91.238     2.76785
             1941  |  -18.80446     23.694    -0.79   0.429     -65.5788    27.96987
             1942  |  -21.13979   23.38163    -0.90   0.367    -67.29748    25.01789
             1943  |  -42.97762   23.55287    -1.82   0.070    -89.47334    3.518104
             1944  |  -43.09876    23.6102    -1.83   0.070    -89.70766    3.510134
             1945  |  -55.68303   23.89561    -2.33   0.021    -102.8554   -8.510689
             1946  |  -31.16928   24.11598    -1.29   0.198    -78.77665    16.43809
             1947  |  -39.39223   23.78368    -1.66   0.100    -86.34361    7.559141
             1948  |  -43.71651   23.96965    -1.82   0.070    -91.03501    3.601991
             1949  |   -73.4951   24.18292    -3.04   0.003    -121.2346   -25.75559
             1950  |  -75.89611   24.34553    -3.12   0.002    -123.9566    -27.8356
             1951  |   -62.4809   24.86425    -2.51   0.013    -111.5654   -13.39637
             1952  |  -64.63233    25.3495    -2.55   0.012    -114.6748   -14.58987
             1953  |  -67.71796   26.61108    -2.54   0.012    -120.2509   -15.18501
             1954  |  -93.52622   27.10786    -3.45   0.001    -147.0399   -40.01257
                   |
             _cons |  -32.83631   18.87533    -1.74   0.084     -70.0981    4.425483
      -------------+----------------------------------------------------------------
           sigma_u |  91.798268
           sigma_e |  51.724523
               rho |  .75902159   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      F test that all u_i=0: F(9, 169) = 52.36                     Prob > F = 0.0000
      
      . xtreg invest L.mvalue kstock i.year, fe
      time variable not set
      r(111);
      
      . xtset company year
      
      Panel variable: company (strongly balanced)
       Time variable: year, 1935 to 1954
               Delta: 1 year
      
      . xtreg invest L.mvalue kstock i.year, fe
      
      Fixed-effects (within) regression               Number of obs     =        190
      Group variable: company                         Number of groups  =         10
      
      R-squared:                                      Obs per group:
           Within  = 0.7383                                         min =         19
           Between = 0.7648                                         avg =       19.0
           Overall = 0.7575                                         max =         19
      
                                                      F(20,160)         =      22.57
      corr(u_i, Xb) = 0.1391                          Prob > F          =     0.0000
      
      ------------------------------------------------------------------------------
            invest | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
      -------------+----------------------------------------------------------------
            mvalue |
               L1. |   .0734322   .0164734     4.46   0.000     .0408989    .1059654
                   |
            kstock |   .3799734   .0264503    14.37   0.000     .3277366    .4322101
                   |
              year |
             1937  |  -17.34644   26.89187    -0.65   0.520    -70.45524    35.76236
             1938  |  -96.17861   28.16239    -3.42   0.001    -151.7966   -40.56066
             1939  |  -62.24324    26.3586    -2.36   0.019    -114.2989   -10.18759
             1940  |   -47.8696   26.88148    -1.78   0.077    -100.9579    5.218677
             1941  |  -32.20724   27.08559    -1.19   0.236    -85.69861    21.28414
             1942  |  -56.13415   26.95485    -2.08   0.039    -109.3673   -2.900986
             1943  |  -49.52305   26.52283    -1.87   0.064     -101.903    2.856935
             1944  |  -54.16445   26.71416    -2.03   0.044    -106.9223   -1.406606
             1945  |  -56.07973   26.81019    -2.09   0.038    -109.0272    -3.13225
             1946  |  -32.61616   27.18962    -1.20   0.232    -86.31298    21.08066
             1947  |  -79.73374   27.64479    -2.88   0.004    -134.3295     -25.138
             1948  |  -68.21684   27.17983    -2.51   0.013    -121.8943   -14.53936
             1949  |  -94.12704   27.39057    -3.44   0.001    -148.2207   -40.03336
             1950  |  -91.47919   27.54807    -3.32   0.001    -145.8839   -37.07446
             1951  |  -55.72503   27.76515    -2.01   0.046    -110.5585   -.8915865
             1952  |   -70.6949   28.69657    -2.46   0.015    -127.3678     -14.022
             1953  |  -52.62905   29.51784    -1.78   0.076    -110.9239    5.665771
             1954  |  -101.3001   31.12203    -3.25   0.001     -162.763   -39.83716
                   |
             _cons |   21.46147   21.69328     0.99   0.324    -21.38061    64.30356
      -------------+----------------------------------------------------------------
           sigma_u |  100.14299
           sigma_e |  58.636411
               rho |  .74468942   (fraction of variance due to u_i)
      ------------------------------------------------------------------------------
      F test that all u_i=0: F(9, 160) = 40.37                     Prob > F = 0.0000
      
      .
      Interestingly, in both cases you can plug -i.year- in the right-hand side of your regression equation as a predictor.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Thanks Andrew and Carlo. I am working with a multinomial reg and I can not use xtmlogit. Could an alternative approach be the adoption of the company id as an additional explanatory variable in your opinion?

        Thanks,
        All the best,
        N

        Comment


        • #5
          Nicola:
          I'm not clear with the reason why you cannot go -xtmlogit-.
          That said, -xtmlogit. and -mlogit- with -i.id- as a predictor give back different results for the shared regressors:
          Code:
          . webuse estatus
          (Fictional employment status data)
          
          .  xtset id
          
          Panel variable: id (unbalanced)
          
          
          . xtmlogit estatus i.hhchild age hhincome i.hhsigno i.bwinner if id<=6, fe
          
          Computing initial values ...
          
          Setting up 245 permutations:
          ....10%....20%....30%....40%....50%....60%....70%....80%....90%....100%
          
          Fitting full model:
          
          Iteration 0:   log likelihood = -17.041558  
          Iteration 1:   log likelihood = -16.848603  
          Iteration 2:   log likelihood = -16.841503  
          Iteration 3:   log likelihood = -16.841495  
          Iteration 4:   log likelihood = -16.841495  
          
          Fixed-effects multinomial logistic regression        Number of obs    =     34
          Group variable: id                                   Number of groups =      6
          
                                                               Obs per group:
                                                                            min =      5
                                                                            avg =    5.7
                                                                            max =      7
          
                                                               LR chi2(10)      =   7.20
          Log likelihood = -16.841495                          Prob > chi2      = 0.7060
          
          ------------------------------------------------------------------------------------
                     estatus | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
          -------------------+----------------------------------------------------------------
          Out_of_labor_force |
                     hhchild |
                        Yes  |   .1660371   1.027042     0.16   0.872    -1.846928    2.179002
                         age |   .1225695   .1418109     0.86   0.387    -.1553748    .4005138
                    hhincome |  -.0199633   .0928036    -0.22   0.830    -.2018551    .1619285
                             |
                     hhsigno |
                        Yes  |   .8759214   .9743157     0.90   0.369    -1.033702    2.785545
                             |
                     bwinner |
                        Yes  |  -.8424123   .9550778    -0.88   0.378     -2.71433    1.029506
          -------------------+----------------------------------------------------------------
          Unemployed         |
                     hhchild |
                        Yes  |   .0180303   2.003351     0.01   0.993    -3.908466    3.944526
                         age |   .3316475   .3304742     1.00   0.316      -.31607     .979365
                    hhincome |   .0239179   .2133791     0.11   0.911    -.3942975    .4421333
                             |
                     hhsigno |
                        Yes  |   .7330291   1.830159     0.40   0.689    -2.854017    4.320075
                             |
                     bwinner |
                        Yes  |  -.9933435   1.862822    -0.53   0.594    -4.644408    2.657721
          -------------------+----------------------------------------------------------------
          Employed           |  (base outcome)
          ------------------------------------------------------------------------------------
          
          . mlogit estatus i.id i.hhchild age hhincome i.hhsigno i.bwinner if id<=6
          
          Iteration 0:   log likelihood = -35.180606  
          Iteration 1:   log likelihood = -27.386876  
          Iteration 2:   log likelihood = -26.131093  
          Iteration 3:   log likelihood = -25.870054  
          Iteration 4:   log likelihood = -25.815955  
          Iteration 5:   log likelihood = -25.805271  
          Iteration 6:   log likelihood = -25.803284  
          Iteration 7:   log likelihood = -25.802839  
          Iteration 8:   log likelihood = -25.802734  
          Iteration 9:   log likelihood = -25.802711  
          Iteration 10:  log likelihood = -25.802706  
          Iteration 11:  log likelihood = -25.802705  
          
          Multinomial logistic regression                         Number of obs =     34
                                                                  LR chi2(20)   =  18.76
                                                                  Prob > chi2   = 0.5377
          Log likelihood = -25.802705                             Pseudo R2     = 0.2666
          
          ------------------------------------------------------------------------------------
                     estatus | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
          -------------------+----------------------------------------------------------------
          Out_of_labor_force |
                          id |
                          2  |  -.6266542   3.683862    -0.17   0.865     -7.84689    6.593582
                          3  |   .9929147   2.711983     0.37   0.714    -4.322474    6.308304
                          4  |   -.970365   3.178538    -0.31   0.760    -7.200185    5.259455
                          5  |  -3.041518   4.266229    -0.71   0.476    -11.40317    5.320137
                          6  |   .0464092   2.716974     0.02   0.986    -5.278761     5.37158
                             |
                     hhchild |
                        Yes  |     .20422   1.149659     0.18   0.859    -2.049071    2.457511
                         age |   .1498789    .157228     0.95   0.340    -.1582824    .4580402
                    hhincome |  -.0247121   .1033132    -0.24   0.811    -.2272023    .1777782
                             |
                     hhsigno |
                        Yes  |   1.102293   1.095312     1.01   0.314    -1.044479    3.249065
                             |
                     bwinner |
                        Yes  |  -1.034203   1.070723    -0.97   0.334    -3.132781    1.064374
                       _cons |  -3.642602   6.905079    -0.53   0.598    -17.17631    9.891105
          -------------------+----------------------------------------------------------------
          Unemployed         |
                          id |
                          2  |   23.62053   4272.265     0.01   0.996    -8349.864    8397.105
                          3  |   23.70214   4272.261     0.01   0.996    -8349.775    8397.179
                          4  |   2.817343   6048.214     0.00   1.000    -11851.47     11857.1
                          5  |   14.40724   4272.275     0.00   0.997    -8359.098    8387.912
                          6  |   21.09611   4272.264     0.00   0.996    -8352.387    8394.579
                             |
                     hhchild |
                        Yes  |   .0741503   2.120479     0.03   0.972    -4.081912    4.230213
                         age |   .4175603   .3756823     1.11   0.266    -.3187635    1.153884
                    hhincome |   .0257051    .243554     0.11   0.916     -.451652    .5030622
                             |
                     hhsigno |
                        Yes  |   1.145913   2.149806     0.53   0.594    -3.067629    5.359456
                             |
                     bwinner |
                        Yes  |  -1.453499   2.054999    -0.71   0.479    -5.481223    2.574226
                       _cons |  -35.97828   4272.277    -0.01   0.993    -8409.487    8337.531
          -------------------+----------------------------------------------------------------
          Employed           |  (base outcome)
          ------------------------------------------------------------------------------------
          
          .
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment

          Working...
          X