Announcement

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

  • Exporting First Stage Results of 2SLS Regression Using XTIVREG

    I am trying to export the results of first stage regression in a word file table. However, using Outreg2 i am only able to get the second stage regression results

    Below is my regression results and the code i ran to extract results to word file

    Code:
    outreg2 using Reg2Event2.doc, append stat(coef tstat) ctitle(2SLS, AEM) addstat("F-statistic", e(F), "R-Squared", e(r2_b)) addtext(Industry Fixed Effect, YES, Year Fixed Effect, NO) dec(4) tdec(2)
    Code:
    xtivreg ABS_DA_w POST_REG INBD POSTREG_X_REM ROA_w Size MTB_x_w LEV_w NOA_X_w (REM_PROXY_w    =    Lag_ABS_DA),    fe    first    small
    
    First-stage within regression
    
    Fixed-effects (within) regression               Number of obs     =      1,315
    Group variable: id                              Number of groups  =        281
    
    R-squared:                                      Obs per group:
    Within  = 0.4889                                         min =          1
    Between = 0.8082                                         avg =        4.7
    Overall = 0.6542                                         max =          8
    
    F(9,1025)         =     108.93
    corr(u_i, Xb) = 0.4034                          Prob > F          =     0.0000
    
    
    REM_PROXY_w  Coefficient  Std. err.      t    P>t     [95% conf. interval]
    
    POST_REG    .0186762   .0080652     2.32   0.021       .00285    .0345024
    INBD    .0783671   .0643577     1.22   0.224    -.0479208    .2046551
    POSTREG_X_REM    .6598204   .0222133    29.70   0.000     .6162317    .7034092
    ROA_w   -.1308316   .0420391    -3.11   0.002    -.2133242    -.048339
    Size    .0271795   .0140415     1.94   0.053    -.0003739    .0547329
    MTB_x_w   -.0133533   .0042623    -3.13   0.002    -.0217171   -.0049895
    LEV_w    -.017941   .0324372    -0.55   0.580    -.0815918    .0457098
    NOA_X_w    .0118952   .0056894     2.09   0.037      .000731    .0230594
    Lag_ABS_DA    .0226871   .0434657     0.52   0.602    -.0626047    .1079789
    _cons   -.4367363   .2118211    -2.06   0.039    -.8523888   -.0210837
    
    sigma_u   .11201445
    sigma_e   .10246778
    rho   .54442229   (fraction of variance due to u_i)
    
    F test that all u_i=0: F(280, 1025) = 3.53                   Prob > F = 0.0000
    
    Fixed-effects (within) IV regression            Number of obs     =      1,315
    Group variable: id                              Number of groups  =        281
    
    R-squared:                                      Obs per group:
    Within  =      .                                         min =          1
    Between = 0.0018                                         avg =        4.7
    Overall = 0.0000                                         max =          8
    
    F(290,1025)       =      0.43
    corr(u_i, Xb) = -0.7818                         Prob > F          =     0.9196
    
    
    ABS_DA_w  Coefficient  Std. err.      t    P>t     [95% conf. interval]
    
    REM_PROXY_w    -3.09999   6.098128    -0.51   0.611    -15.06623    8.866251
    POST_REG    .0653209   .1154681     0.57   0.572      -.16126    .2919018
    INBD    .2044777   .5204369     0.39   0.694    -.8167657    1.225721
    POSTREG_X_REM    2.040223   4.023804     0.51   0.612    -5.855611    9.936058
    ROA_w   -.6007786   .7939438    -0.76   0.449    -2.158719    .9571623
    Size    .1016277   .1747267     0.58   0.561    -.2412353    .4444907
    MTB_x_w   -.0389572   .0808277    -0.48   0.630    -.1975638    .1196495
    LEV_w    -.031798   .1456086    -0.22   0.827     -.317523     .253927
    NOA_X_w    .0354542   .0755283     0.47   0.639    -.1127536    .1836621
    _cons   -1.526531   2.788213    -0.55   0.584    -6.997789    3.944727
    
    sigma_u   .36017545
    sigma_e   .32614935
    rho    .5494557   (fraction of variance due to u_i)
    
    F test that all u_i=0: F(280,1025) =     0.09            Prob > F    = 1.0000
    
    Instrumented: REM_PROXY_w
    Instruments: POST_REG INBD POSTREG_X_REM ROA_w Size MTB_x_w LEV_w NOA_X_w
    Lag_ABS_DA
    Any help would be helpful. Thank you

  • #2
    outreg2 is from SSC, as you are asked to explain. Perhaps just run the first stage using xtreg.

    Code:
    webuse nlswork, clear
    xtset idcode year
    xtivreg ln_w age c.age#c.age not_smsa (tenure = union south), fe first
    est sto second
    xtreg `e(instd)' `e(insts)' if e(sample), fe
    est sto first
    outreg2 [first second] using myfile.rtf, replace nocons
    Res.:

    Code:
    . 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
    ------------------------------------------------------------------------------
    Instrumented: tenure
     Instruments: age c.age#c.age not_smsa union south
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	12.5 KB
ID:	1687989

    Last edited by Andrew Musau; 04 Nov 2022, 04:03.

    Comment


    • #3
      Andrew Musau Thank you Andrew for your kind help. This works perfectly as the run the regressions.

      Comment


      • #4
        how to report 2nd stage R-squared in this case?

        Comment


        • #5
          Code:
          ssc install estout, replace
          Code:
          webuse nlswork, clear
          xtset idcode year
          xtivreg ln_w age c.age#c.age not_smsa (tenure = union south), fe first
          estadd scalar r2= e(r2_w)
          est sto second
          xtreg `e(instd)' `e(insts)' if e(sample), fe
          est sto first
          outreg2 [first second] using myfile.rtf, replace nocons

          Comment


          • #6
            thank you so much, that helped me much. however when trying to make sure of the numbers exported, the coefficients are the same however the t-tests are different. the ones reported in the first stage xtivreg command is different from that reported by "xtreg `e(instd)' `e(insts)' if e(sample), fe" why is that ?. moreover, if i want to report the postestimation results from the xtoverid,nois how to add this to the outreg2 . your help is much appreciated.

            Comment


            • #7
              I specifically want to export the Hansen j test the weak identification and the under identification and finally the f statistic of the first stage. i found your suggested code of the return list then outreg2 however this reported only the hansen j statistic along its chi-square.

              Comment


              • #8
                #4 gives a general approach: https://www.statalist.org/forums/for...-stage-outcome. If you can extract one statistic, you can extract them all.

                Comment


                • #9
                  and what about the differences in the t-statistics obtained from the first stage regression using the XTIVREG and that one "xtreg `e(instd)' `e(insts)' if e(sample), fe"

                  Comment


                  • #10
                    I do not spot any differences (see highlighted). Elaborate on your point.

                    Code:
                    webuse nlswork, clear
                    xtset idcode year
                    xtivreg ln_w age c.age#c.age not_smsa (tenure = union south), fe first
                    xtreg `e(instd)' `e(insts)' if e(sample), fe
                    Res.:

                    Code:
                    . 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
                    ------------------------------------------------------------------------------
                    Instrumented: tenure
                     Instruments: age c.age#c.age not_smsa union south
                    
                    . 
                    . xtreg `e(instd)' `e(insts)' if e(sample), fe
                    
                    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
                    
                    .

                    Comment


                    • #11
                      I have managed to solve the problem of the difference in the t-statistic. my question now is how to export the postestimation results after the xtoverid,nois. the link you have suggested is working on xtivreg2 not xtivreg. when trying the ereturn list, it did not include the Hansen J and the overidentification tests. any suggestions is much appreciated?

                      Comment


                      • #12
                        https://www.statalist.org/forums/for...overid-command

                        Comment


                        • #13
                          I am sorry for asking too many questions, but i have been stuck in this for couple of days. how to export the Kleibergen-Paap rk LM statistic,Cragg-Donald Wald F statistic,Kleibergen-Paap rk Wald F statistic and the f statistic of the first stage. another question is related to the xtivreg2 command, its easier because it can directly export the postestimation results. however i faced two problems with it. the first one is related to the number of observations and clusters as they are different from that reported in xtivreg. i tried the commands you have suggested in one of the forums(using xtreg to get the first stage) yet it doesn't yield the same results. the other question is related to the constant and the R-squared, for the constant using xtivreg2 its not reported in the first or 2nd stage. as for the r-squared of the first stage its also not reported. any help is appreciated?

                          Comment

                          Working...
                          X