Announcement

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

  • How to export results from xtivreg using esttab

    Hi everyone,
    I'm running the following instrumental variable regression:
    Code:
    xtivreg sust (cash = mean_cash) cap i.year, fe first
    Now, I'd like to export the results of both the first and second-stage regression (with F-stat from the first-stage regression) using esttab. Do you have any suggestions on how to do it?

    Thank you so much for the help!

  • #2
    estout is from SSC (FAQ Advice #12).

    Code:
    webuse nlswork, clear
    eststo second: xtivreg ln_w age c.age#c.age not_smsa (tenure = union south), fe first
    eststo first: qui xtreg `e(instd)' `e(insts)' if e(sample), fe
    esttab first second, drop(_cons) scalars(N F) label
    Res.:

    Code:
    . eststo second: xtivreg ln_w age c.age#c.age not_smsa (tenure = union south), fe first
    
    First-stage within regression
    
    Fixed-effects (within) regression               Number of obs     =     19,007
    Group variable: idcode                          Number of groups  =      4,134
    
    R-squared:                                      Obs per group:
         Within  = 0.3019                                         min =          1
         Between = 0.0578                                         avg =        4.6
         Overall = 0.1289                                         max =         12
    
                                                    F(5, 14868)       =    1285.83
    corr(u_i, Xb) = -0.1871                         Prob > F          =     0.0000
    
    ------------------------------------------------------------------------------
          tenure | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             age |   .0863031   .0343238     2.51   0.012     .0190241    .1535821
                 |
     c.age#c.age |   .0039115    .000549     7.12   0.000     .0028353    .0049876
                 |
        not_smsa |  -.3552488   .1269318    -2.80   0.005    -.6040507   -.1064468
           union |   .3896861   .0706568     5.52   0.000     .2511901    .5281821
           south |  -.4296172   .1349122    -3.18   0.001    -.6940618   -.1651726
           _cons |  -2.554764   .5293374    -4.83   0.000     -3.59233   -1.517197
    -------------+----------------------------------------------------------------
         sigma_u |  3.1334845
         sigma_e |  2.5869529
             rho |  .59467598   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
    F test that all u_i=0: F(4133, 14868) = 6.40                 Prob > F = 0.0000
    
    Fixed-effects (within) IV regression            Number of obs     =     19,007
    Group variable: idcode                          Number of groups  =      4,134
    
    R-squared:                                      Obs per group:
         Within  =      .                                         min =          1
         Between = 0.1304                                         avg =        4.6
         Overall = 0.0897                                         max =         12
    
                                                    Wald chi2(4)      =  147926.58
    corr(u_i, Xb) = -0.6843                         Prob > chi2       =     0.0000
    
    ------------------------------------------------------------------------------
         ln_wage | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          tenure |   .2403531   .0373419     6.44   0.000     .1671643    .3135419
             age |   .0118437   .0090032     1.32   0.188    -.0058023    .0294897
                 |
     c.age#c.age |  -.0012145   .0001968    -6.17   0.000    -.0016003   -.0008286
                 |
        not_smsa |  -.0167178   .0339236    -0.49   0.622    -.0832069    .0497713
           _cons |   1.678287   .1626657    10.32   0.000     1.359468    1.997106
    -------------+----------------------------------------------------------------
         sigma_u |  .70661941
         sigma_e |  .63029359
             rho |  .55690561   (fraction of variance due to u_i)
    ------------------------------------------------------------------------------
     F test that all u_i=0: F(4133,14869) =     1.44          Prob > F    = 0.0000
    ------------------------------------------------------------------------------
    Endogenous: tenure
    Exogenous:  age c.age#c.age not_smsa union south
    
    . 
    . eststo first: qui xtreg `e(instd)' `e(insts)' if e(sample), fe
    
    . 
    . esttab first second, drop(_cons) scalars(N F) label
    
    ----------------------------------------------------
                                  (1)             (2)   
                         Job tenure~s    ln(wage/GN~)   
    ----------------------------------------------------
    Age in current year        0.0863*         0.0118   
                               (2.51)          (1.32)   
    
    Age in current yea~r      0.00391***     -0.00121***
                               (7.12)         (-6.17)   
    
    1 if not SMSA              -0.355**       -0.0167   
                              (-2.80)         (-0.49)   
    
    1 if union                  0.390***                
                               (5.52)                   
    
    1 if south                 -0.430**                 
                              (-3.18)                   
    
    Job tenure, in years                        0.240***
                                               (6.44)   
    ----------------------------------------------------
    Observations                19007           19007   
    F                          1285.8                   
    ----------------------------------------------------
    t statistics in parentheses
    * p<0.05, ** p<0.01, *** p<0.001
    Last edited by Andrew Musau; 28 Feb 2024, 08:32.

    Comment


    • #3
      Thank you Andrew for your reply! I tried to run the same commands using my own regression:
      Code:
      est clear
      eststo second: xtivreg sust (cash = mean_cash) cap i.year, fe first
      eststo first: qui xtreg `e(instd)' `e(insts)' if e(sample), fe
      esttab first second, drop(_cons) scalars(N F) label
      The only problem is that the coefficients and the F-statistic from the first-stage regression printed in the table are different from the ones reported in the Stata output above. There is a mismatch between what I can see from the first-stage regression using xtivreg and what I find in the table from esttab. How is it possible?

      Thank you!

      Comment


      • #4
        It does not happen with my example in #2. Can you provide a reproducible example that illustrates this? If you can share your data, copy and paste the result of the following:

        Code:
        qui xtset
        dataex `r(panelvar)' sust cash  mean_cash cap year

        Comment


        • #5
          Dear Andrew,
          I think the problem is related to the usage of time operators. Indeed, the regression I have to run is the following:
          Code:
          . est clear
          
          . eststo second: xtivreg sust (l.cash = l.mean_cash) l.cap i.year, fe first
          
          First-stage within regression
          
          Fixed-effects (within) regression               Number of obs     =     18,574
          Group variable: company_id                      Number of groups  =      3,903
          
          R-squared:                                      Obs per group:
               Within  = 0.0315                                         min =          1
               Between = 0.2124                                         avg =        4.8
               Overall = 0.1553                                         max =         11
          
                                                          F(12,14659)       =      39.74
          corr(u_i, Xb) = 0.2820                          Prob > F          =     0.0000
          
          ------------------------------------------------------------------------------
              __000004 | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                   cap |
                   L1. |  -.0407847   .0047118    -8.66   0.000    -.0500205    -.031549
                       |
                  year |
                 2011  |          0  (empty)
                 2012  |  -.0138531   .0023578    -5.88   0.000    -.0184747   -.0092315
                 2013  |  -.0198712   .0024981    -7.95   0.000    -.0247677   -.0149747
                 2014  |  -.0140905   .0024294    -5.80   0.000    -.0188523   -.0093286
                 2015  |  -.0121639   .0023108    -5.26   0.000    -.0166933   -.0076345
                 2016  |  -.0111176   .0022791    -4.88   0.000    -.0155849   -.0066502
                 2017  |  -.0102835   .0021377    -4.81   0.000    -.0144736   -.0060933
                 2018  |   -.007541   .0020314    -3.71   0.000    -.0115227   -.0035593
                 2019  |  -.0155915   .0020651    -7.55   0.000    -.0196394   -.0115436
                 2020  |   -.020013   .0020436    -9.79   0.000    -.0240187   -.0160072
                 2021  |   .0005053   .0016177     0.31   0.755    -.0026657    .0036762
                 2022  |          0  (omitted)
                       |
             mean_cash |
                   L1. |   .1416309   .0406277     3.49   0.000     .0619955    .2212662
                       |
                 _cons |   .1288699   .0077376    16.65   0.000     .1137031    .1440366
          -------------+----------------------------------------------------------------
               sigma_u |  .12023968
               sigma_e |  .05146785
                   rho |  .84515028   (fraction of variance due to u_i)
          ------------------------------------------------------------------------------
          F test that all u_i=0: F(3902, 14659) = 16.73                Prob > F = 0.0000
          
          Fixed-effects (within) IV regression            Number of obs     =     23,688
          Group variable: company_id                      Number of groups  =      4,592
          
          R-squared:                                      Obs per group:
               Within  =      .                                         min =          1
               Between = 0.0002                                         avg =        5.2
               Overall = 0.0001                                         max =         12
          
                                                          Wald chi2(13)     =     431.32
          corr(u_i, Xb) = -0.0091                         Prob > chi2       =     0.0000
          
          ------------------------------------------------------------------------------
                  sust | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
          -------------+----------------------------------------------------------------
                  cash |
                   L1. |  -155.8727   305.0177    -0.51   0.609    -753.6965    441.9511
                       |
                   cap |
                   L1. |  -8.822369   16.82683    -0.52   0.600    -41.80235    24.15761
                       |
                  year |
                 2012  |  -.7883762   3.491579    -0.23   0.821    -7.631744    6.054992
                 2013  |  -2.038703   5.212085    -0.39   0.696     -12.2542    8.176796
                 2014  |   -1.01614   3.811966    -0.27   0.790    -8.487455    6.455176
                 2015  |  -.5365042   3.295733    -0.16   0.871    -6.996023    5.923015
                 2016  |  -.4987909   3.206532    -0.16   0.876    -6.783478    5.785896
                 2017  |  -.7228866   3.012198    -0.24   0.810    -6.626686    5.180913
                 2018  |  -.3154553   2.836694    -0.11   0.911    -5.875274    5.244363
                 2019  |  -1.508924   3.879447    -0.39   0.697    -9.112501    6.094653
                 2020  |  -1.447044   5.009101    -0.29   0.773     -11.2647    8.370613
                 2021  |   3.968255   4.071182     0.97   0.330    -4.011115    11.94762
                 2022  |  -2.199229   4.163453    -0.53   0.597    -10.35945    5.960989
                       |
                 _cons |   33.19626   46.27593     0.72   0.473    -57.50289    123.8954
          -------------+----------------------------------------------------------------
               sigma_u |   1462.871
               sigma_e |  71.025753
                   rho |  .99764822   (fraction of variance due to u_i)
          ------------------------------------------------------------------------------
           F test that all u_i=0: F(4591,19083) =   846.49          Prob > F    = 0.0000
          ------------------------------------------------------------------------------
          Instrumented: L.cash
           Instruments: L.cap 2012.year 2013.year 2014.year 2015.year 2016.year
                        2017.year 2018.year 2019.year 2020.year 2021.year 2022.year
                        L.mean_cash
          
          . do "C:\Users\marti\AppData\Local\Temp\STD32e8_000000.tmp"
          
          . eststo first: qui xtreg `e(instd)' `e(insts)' if e(sample), fe
          
          . 
          end of do-file
          
          . esttab first second, drop(_cons) scalars(N F) label
          
          ----------------------------------------------------
                                        (1)             (2)   
                                     L.cash            sust   
          ----------------------------------------------------
          L.cap                     -0.0518***       -8.822   
                                   (-12.67)         (-0.52)   
          
          year=2011                       0               0   
                                        (.)             (.)   
          
          year=2012                -0.00512*         -0.788   
                                    (-2.12)         (-0.23)   
          
          year=2013                 -0.0117***       -2.039   
                                    (-4.73)         (-0.39)   
          
          year=2014                -0.00547*         -1.016   
                                    (-2.23)         (-0.27)   
          
          year=2015                -0.00310          -0.537   
                                    (-1.31)         (-0.16)   
          
          year=2016                -0.00222          -0.499   
                                    (-0.95)         (-0.16)   
          
          year=2017                -0.00167          -0.723   
                                    (-0.74)         (-0.24)   
          
          year=2018                0.000119          -0.315   
                                     (0.05)         (-0.11)   
          
          year=2019                -0.00707**        -1.509   
                                    (-3.25)         (-0.39)   
          
          year=2020                 -0.0114***       -1.447   
                                    (-5.21)         (-0.29)   
          
          year=2021                 0.00863***        3.968   
                                     (4.03)          (0.97)   
          
          year=2022                 0.00760**        -2.199   
                                     (3.25)         (-0.53)   
          
          L.mean_cash                 0.152***                
                                     (4.25)                   
          
          L.cash                                     -155.9   
                                                    (-0.51)   
          ----------------------------------------------------
          Observations                23688           23688   
          F                           46.64                   
          ----------------------------------------------------
          t statistics in parentheses
          * p<0.05, ** p<0.01, *** p<0.001
          As you can see, results are not consistent. However, if I eliminate lagged operators, the problem is solved. Is there a way to use your code when there are lagged variables in the regression?
          Thank you!


          Comment


          • #6
            See #7: https://www.statalist.org/forums/for...he-first-stage

            Comment


            • #7
              Dear Andrew,
              now it works, thank you so much! I have just one additional question: is it ok if the number of observations is different in the first and second-stage regression (17958 vs. 22993)?

              Thank you!

              Comment


              • #8
                Yes, that's fine. You may add an explanation that the difference is caused by lagging variables if you report both. I would just report the second stage \(N\).

                Comment


                • #9
                  Thank you Andrew for your help!

                  Comment

                  Working...
                  X