Announcement

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

  • Replicate ivprobit results using gsem

    Hi,

    I would like to run two equivalent commands using ivprobit and gsem, but I am failing to obtaining the same results.

    Here is my attempt:

    Code:
    clear all
    webuse laborsup
    ivprobit fem_work (other_inc = male_educ) fem_educ kids, first
    gsem    (fem_work <- other_inc fem_educ kids L@1, probit) ///
            (other_inc <- fem_educ kids male_educ), ///
            var(L@1)
    These are the results:
    Code:
    . clear all
    
    . webuse laborsup
    
    . ivprobit fem_work (other_inc = male_educ) fem_educ kids, first
    
    Fitting exogenous probit model
    
    Iteration 0:   log likelihood = -344.63508  
    Iteration 1:   log likelihood = -252.10819  
    Iteration 2:   log likelihood = -252.04529  
    Iteration 3:   log likelihood = -252.04529  
    
    Fitting full model
    
    Iteration 0:   log likelihood = -2368.2142  
    Iteration 1:   log likelihood = -2368.2062  
    Iteration 2:   log likelihood = -2368.2062  
    
    Probit model with endogenous regressors                 Number of obs =    500
                                                            Wald chi2(3)  = 163.88
    Log likelihood = -2368.2062                             Prob > chi2   = 0.0000
    
    ----------------------------------------------------------------------------------------------
                                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -----------------------------+----------------------------------------------------------------
    fem_work                     |
                       other_inc |  -.0542756   .0060854    -8.92   0.000    -.0662028   -.0423485
                        fem_educ |    .211111   .0268648     7.86   0.000     .1584569    .2637651
                            kids |  -.1820929   .0478267    -3.81   0.000    -.2758315   -.0883542
                           _cons |   .3672086   .4480724     0.82   0.412    -.5109971    1.245414
    -----------------------------+----------------------------------------------------------------
    other_inc                    |
                        fem_educ |   .3351866   .2825972     1.19   0.236    -.2186937     .889067
                            kids |   .8329056   .5475666     1.52   0.128    -.2403052    1.906116
                       male_educ |   2.845253    .282746    10.06   0.000     2.291081    3.399425
                           _cons |   9.872562   5.029193     1.96   0.050     .0155242     19.7296
    -----------------------------+----------------------------------------------------------------
                      /athrho2_1 |   .3907859   .1509443     2.59   0.010     .0949404    .6866313
                       /lnsigma2 |   2.813383   .0316228    88.97   0.000     2.751404    2.875363
    -----------------------------+----------------------------------------------------------------
     corr(e.other_inc,e.fem_work)|   .3720375   .1300518                      .0946562    .5958136
                  sd(e.other_inc)|   16.66621   .5270318                      15.66461    17.73186
    ----------------------------------------------------------------------------------------------
    Wald test of exogeneity (corr = 0): chi2(1) = 6.70        Prob > chi2 = 0.0096
    Instrumented: other_inc
     Instruments: fem_educ kids male_educ
    
    . gsem    (fem_work <- other_inc fem_educ kids L@1, probit) ///
    >                 (other_inc <- fem_educ kids male_educ), ///
    >                 var(L@1)
    
    Fitting fixed-effects model:
    
    Iteration 0:   log likelihood = -2373.0212  
    Iteration 1:   log likelihood = -2371.4789  
    Iteration 2:   log likelihood = -2371.4753  
    Iteration 3:   log likelihood = -2371.4753  
    
    Refining starting values:
    
    Grid node 0:   log likelihood = -2377.7146
    
    Fitting full model:
    
    Iteration 0:   log likelihood = -2377.7146  
    Iteration 1:   log likelihood = -2371.4764  
    Iteration 2:   log likelihood = -2371.4747  
    Iteration 3:   log likelihood = -2371.4747  
    
    Generalized structural equation model                      Number of obs = 500
    
    Response: fem_work
    Family:   Bernoulli
    Link:     Probit  
    
    Response: other_inc
    Family:   Gaussian
    Link:     Identity
    
    Log likelihood = -2371.4747
    
     ( 1)  [fem_work]L = 1
     ( 2)  [/]var(L) = 1
    ----------------------------------------------------------------------------------
                     | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -----------------+----------------------------------------------------------------
    fem_work         |
           other_inc |  -.0540839   .0057625    -9.39   0.000    -.0653782   -.0427896
            fem_educ |    .307729   .0376262     8.18   0.000     .2339831    .3814749
                kids |  -.2908398   .0669661    -4.34   0.000     -.422091   -.1595886
                   L |          1  (constrained)
               _cons |  -.6589946   .4799027    -1.37   0.170    -1.599587    .2815973
    -----------------+----------------------------------------------------------------
    other_inc        |
            fem_educ |   .3351866   .2825972     1.19   0.236    -.2186937     .889067
                kids |   .8329056   .5475666     1.52   0.128    -.2403052    1.906116
           male_educ |   2.845253    .282746    10.06   0.000     2.291081    3.399425
               _cons |   9.872562   5.029193     1.96   0.050     .0155242     19.7296
    -----------------+----------------------------------------------------------------
               var(L)|          1  (constrained)
    -----------------+----------------------------------------------------------------
     var(e.other_inc)|   277.7625   17.56725                      245.3799    314.4187
    ----------------------------------------------------------------------------------

    Can anybody help with this?
    Last edited by Lukas Lang; 31 May 2023, 07:33.
    ------
    I use Stata 17

  • #2
    Hi,

    I have made some progress, but I have not sorted my real problem.

    It seems we can induce gsem to produce results that are equivalent to ivprobit in the case of one endogenous variable as follows:

    Code:
    clear all
    webuse laborsup
    ivprobit fem_work (other_inc = male_educ) fem_educ kids, first
    gsem    (fem_work <- other_inc fem_educ kids L@1, probit) ///
            (other_inc <- fem_educ kids male_educ L), ///
            var(L@1)
    nlcom    (fem_educ : _b[fem_work:other_inc] / sqrt(2)) ///
            (fem_educ : _b[fem_work:fem_educ] / sqrt(2)) ///
            (kids : _b[fem_work:kids] / sqrt(2)) ///
            (cons : _b[fem_work:_cons] / sqrt(2))

    The results are:

    Code:
    . clear all
    
    . webuse laborsup
    
    . ivprobit fem_work (other_inc = male_educ) fem_educ kids, first
    
    Fitting exogenous probit model
    
    Iteration 0:   log likelihood = -344.63508  
    Iteration 1:   log likelihood = -252.10819  
    Iteration 2:   log likelihood = -252.04529  
    Iteration 3:   log likelihood = -252.04529  
    
    Fitting full model
    
    Iteration 0:   log likelihood = -2368.2142  
    Iteration 1:   log likelihood = -2368.2062  
    Iteration 2:   log likelihood = -2368.2062  
    
    Probit model with endogenous regressors                 Number of obs =    500
                                                            Wald chi2(3)  = 163.88
    Log likelihood = -2368.2062                             Prob > chi2   = 0.0000
    
    -------------------------------------------------------------------------------
                  | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    --------------+----------------------------------------------------------------
    fem_work      |
        other_inc |  -.0542756   .0060854    -8.92   0.000    -.0662028   -.0423485
         fem_educ |    .211111   .0268648     7.86   0.000     .1584569    .2637651
             kids |  -.1820929   .0478267    -3.81   0.000    -.2758315   -.0883542
            _cons |   .3672086   .4480724     0.82   0.412    -.5109971    1.245414
    --------------+----------------------------------------------------------------
    other_inc     |
         fem_educ |   .3351866   .2825972     1.19   0.236    -.2186937     .889067
             kids |   .8329056   .5475666     1.52   0.128    -.2403052    1.906116
        male_educ |   2.845253    .282746    10.06   0.000     2.291081    3.399425
            _cons |   9.872562   5.029193     1.96   0.050     .0155242     19.7296
    --------------+----------------------------------------------------------------
       /athrho2_1 |   .3907859   .1509443     2.59   0.010     .0949404    .6866313
        /lnsigma2 |   2.813383   .0316228    88.97   0.000     2.751404    2.875363
    --------------+----------------------------------------------------------------
    corr(e.othe~c,|
       e.fem_work)|   .3720375   .1300518                      .0946562    .5958136
    sd(e.other_~c)|   16.66621   .5270318                      15.66461    17.73186
    -------------------------------------------------------------------------------
    Wald test of exogeneity (corr = 0): chi2(1) = 6.70        Prob > chi2 = 0.0096
    Instrumented: other_inc
     Instruments: fem_educ kids male_educ
    
    . gsem    (fem_work <- other_inc fem_educ kids L@1, probit) ///
    >         (other_inc <- fem_educ kids male_educ L), ///
    >         var(L@1)
    
    Fitting fixed-effects model:
    
    Iteration 0:   log likelihood = -2373.0212  
    Iteration 1:   log likelihood = -2371.4789  
    Iteration 2:   log likelihood = -2371.4753  
    Iteration 3:   log likelihood = -2371.4753  
    
    Refining starting values:
    
    Grid node 0:   log likelihood = -2377.8837
    
    Fitting full model:
    
    Iteration 0:   log likelihood = -2377.8837  
    Iteration 1:   log likelihood = -2375.2652  
    Iteration 2:   log likelihood = -2368.7263  (not concave)
    Iteration 3:   log likelihood = -2368.3357  
    Iteration 4:   log likelihood = -2368.2452  
    Iteration 5:   log likelihood = -2368.2063  
    Iteration 6:   log likelihood = -2368.2061  
    
    Generalized structural equation model                      Number of obs = 500
    
    Response: fem_work
    Family:   Bernoulli
    Link:     Probit  
    
    Response: other_inc
    Family:   Gaussian
    Link:     Identity
    
    Log likelihood = -2368.2061
    
     ( 1)  [fem_work]L = 1
     ( 2)  [/]var(L) = 1
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    fem_work     |
       other_inc |  -.0767588   .0086034    -8.92   0.000    -.0936212   -.0598964
        fem_educ |   .2985556   .0379894     7.86   0.000     .2240978    .3730133
            kids |  -.2575158   .0676328    -3.81   0.000    -.3900736    -.124958
               L |          1  (constrained)
           _cons |   .5193852   .6334912     0.82   0.412    -.7222347    1.761005
    -------------+----------------------------------------------------------------
    other_inc    |
        fem_educ |   .3351903   .2825977     1.19   0.236    -.2186911    .8890717
            kids |   .8329029   .5475682     1.52   0.128    -.2403109    1.906117
       male_educ |    2.84525   .2827427    10.06   0.000     2.291084    3.399415
               L |   8.769337   3.097587     2.83   0.005     2.698178     14.8405
           _cons |   9.872564   5.029133     1.96   0.050     .0156446    19.72948
    -------------+----------------------------------------------------------------
           var(L)|          1  (constrained)
    -------------+----------------------------------------------------------------
    var(e.othe~c)|   200.8641   54.24256                      118.3147     341.009
    ------------------------------------------------------------------------------
    
    . nlcom   (fem_educ : _b[fem_work:other_inc] / sqrt(2)) ///
    >                 (fem_educ : _b[fem_work:fem_educ] / sqrt(2)) ///
    >                 (kids : _b[fem_work:kids] / sqrt(2)) ///
    >                 (cons : _b[fem_work:_cons] / sqrt(2))
    
        fem_educ: _b[fem_work:other_inc] / sqrt(2)
        fem_educ: _b[fem_work:fem_educ] / sqrt(2)
            kids: _b[fem_work:kids] / sqrt(2)
            cons: _b[fem_work:_cons] / sqrt(2)
    
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
        fem_educ |  -.0542767   .0060835    -8.92   0.000    -.0662002   -.0423532
        fem_educ |   .2111107   .0268625     7.86   0.000     .1584611    .2637603
            kids |  -.1820912   .0478236    -3.81   0.000    -.2758237   -.0883587
            cons |   .3672608   .4479459     0.82   0.412     -.510697    1.245219
    ------------------------------------------------------------------------------

    In the other_inc equation, we can add a latent variable (L) and we can then transform the gsem coefficients to obtain the ivprobit coefficients

    However, why is this trick not working when we have multiple endogeonus variables (which is my actual problem)?

    See the following example:

    Code:
    gen new_iv=runiform(1, 2)
    ivprobit fem_work (other_inc fem_educ = male_educ new_iv) kids, first
    gsem    (fem_work <- other_inc fem_educ kids L@1, probit) ///
            (other_inc <- kids male_educ new_iv L) ///
            (fem_educ <- kids male_educ new_iv L), ///
            var(L@1)

    In this case, the results are:

    Code:
    . gen new_iv=runiform(1, 2)
    
    . ivprobit fem_work (other_inc fem_educ = male_educ new_iv) kids, first
    
    Fitting exogenous probit model
    
    Iteration 0:   log likelihood = -344.63508  
    Iteration 1:   log likelihood = -252.08506  
    Iteration 2:   log likelihood = -252.02331  
    Iteration 3:   log likelihood = -252.02331  
    
    Fitting full model
    
    Iteration 0:   log likelihood = -3561.6983  
    Iteration 1:   log likelihood = -3561.6822  
    Iteration 2:   log likelihood = -3561.6822  
    
    Probit model with endogenous regressors                 Number of obs =    500
                                                            Wald chi2(3)  = 176.15
    Log likelihood = -3561.6822                             Prob > chi2   = 0.0000
    
    -------------------------------------------------------------------------------
                  | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    --------------+----------------------------------------------------------------
    fem_work      |
        other_inc |  -.0502853   .0216314    -2.32   0.020    -.0926821   -.0078885
         fem_educ |   .3279882   .2941496     1.12   0.265    -.2485345    .9045108
             kids |  -.1813605    .058115    -3.12   0.002    -.2952639   -.0674571
            _cons |  -1.232472   4.602739    -0.27   0.789    -10.25368    7.788731
    --------------+----------------------------------------------------------------
    other_inc     |
             kids |   .8361891   .5488621     1.52   0.128    -.2395608    1.911939
        male_educ |   2.828898   .2833297     9.98   0.000     2.273582    3.384214
           new_iv |   1.353638   2.586518     0.52   0.601    -3.715845    6.423121
            _cons |   12.09435    5.12694     2.36   0.018     2.045734    22.14297
    --------------+----------------------------------------------------------------
    fem_educ      |
             kids |    .053571   .0866261     0.62   0.536     -.116213     .223355
        male_educ |  -.0292372   .0447175    -0.65   0.513    -.1168819    .0584075
           new_iv |   .5076314   .4082263     1.24   0.214    -.2924774     1.30774
            _cons |   11.53806   .8091772    14.26   0.000     9.952105    13.12402
    --------------+----------------------------------------------------------------
       /athrho2_1 |   .3262499   .2833922     1.15   0.250    -.2291886    .8816885
       /athrho3_1 |  -.3523941   1.081658    -0.33   0.745    -2.472405    1.767616
       /athrho3_2 |   .0518104   .0447214     1.16   0.247    -.0358419    .1394626
        /lnsigma2 |   2.814514   .0316228    89.00   0.000     2.752535    2.876494
        /lnsigma3 |    .968268   .0316228    30.62   0.000     .9062885    1.030247
    --------------+----------------------------------------------------------------
    corr(e.othe~c,|
       e.fem_work)|   .3151472   .2552464                     -.2252583    .7072642
    corr(e.fem~uc,|
       e.fem_work)|  -.3384971   .9577213                     -.9858601    .9433476
    corr(e.fem~uc,|
      e.other_inc)|    .051764   .0446015                     -.0358266    .1385654
    sd(e.other_~c)|   16.68507   .5276282                      15.68233    17.75192
    sd(e.fem_educ)|   2.633379   .0832748                      2.475119    2.801759
    -------------------------------------------------------------------------------
    Wald test of exogeneity: chi2(2) = 8.27                   Prob > chi2 = 0.0160
    Instrumented: other_inc fem_educ
     Instruments: kids male_educ new_iv
    
    . gsem    (fem_work <- other_inc fem_educ kids L@1, probit) ///
    >         (other_inc <- kids male_educ new_iv L) ///
    >         (fem_educ <- kids male_educ new_iv L), ///
    >         var(L@1)
    
    Fitting fixed-effects model:
    
    Iteration 0:   log likelihood =   -3567.19  
    Iteration 1:   log likelihood = -3565.6477  
    Iteration 2:   log likelihood = -3565.6441  
    Iteration 3:   log likelihood = -3565.6441  
    
    Refining starting values:
    
    Grid node 0:   log likelihood = -3592.1953
    
    Fitting full model:
    
    Iteration 0:   log likelihood = -3592.1953  (not concave)
    Iteration 1:   log likelihood = -3570.3565  (not concave)
    Iteration 2:   log likelihood =  -3568.212  (not concave)
    Iteration 3:   log likelihood = -3567.4249  (not concave)
    Iteration 4:   log likelihood = -3566.8534  (not concave)
    Iteration 5:   log likelihood = -3566.4715  (not concave)
    Iteration 6:   log likelihood = -3566.0964  (not concave)
    Iteration 7:   log likelihood = -3564.8077  
    Iteration 8:   log likelihood = -3563.1887  
    Iteration 9:   log likelihood = -3562.4282  
    Iteration 10:  log likelihood = -3561.7669  
    Iteration 11:  log likelihood = -3561.7567  
    Iteration 12:  log likelihood = -3561.7565  
    
    Generalized structural equation model                      Number of obs = 500
    
    Response: fem_work
    Family:   Bernoulli
    Link:     Probit  
    
    Response: other_inc
    Family:   Gaussian
    Link:     Identity
    
    Response: fem_educ
    Family:   Gaussian
    Link:     Identity
    
    Log likelihood = -3561.7565
    
     ( 1)  [fem_work]L = 1
     ( 2)  [/]var(L) = 1
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
    fem_work     |
       other_inc |  -.0767468   .0085912    -8.93   0.000    -.0935854   -.0599083
        fem_educ |   .2610255   .0424455     6.15   0.000     .1778339    .3442172
            kids |  -.2541954   .0672316    -3.78   0.000     -.385967   -.1224238
               L |          1  (constrained)
           _cons |   .9647083   .5966083     1.62   0.106    -.2046224    2.134039
    -------------+----------------------------------------------------------------
    other_inc    |
            kids |   .8395442   .5487988     1.53   0.126    -.2360818     1.91517
       male_educ |   2.830935   .2830593    10.00   0.000     2.276149     3.38572
          new_iv |   1.084682    2.49373     0.43   0.664    -3.802939    5.972303
               L |   8.881188    3.04594     2.92   0.004     2.911255    14.85112
           _cons |   12.46174   5.062753     2.46   0.014     2.538929    22.38456
    -------------+----------------------------------------------------------------
    fem_educ     |
            kids |   .0536665   .0866259     0.62   0.536     -.116117    .2234501
       male_educ |  -.0291795   .0447179    -0.65   0.514    -.1168249     .058466
          new_iv |   .4999718   .4078124     1.23   0.220    -.2993257    1.299269
               L |   .2529253    .233157     1.08   0.278    -.2040539    .7099046
           _cons |   11.54853   .8086922    14.28   0.000     9.963521    13.13354
    -------------+----------------------------------------------------------------
           var(L)|          1  (constrained)
    -------------+----------------------------------------------------------------
    var(e.othe~c)|   199.5276   53.95235                      117.4459    338.9755
    var(e.fem~uc)|   6.870726   .4463382                      6.049321    7.803666
    ------------------------------------------------------------------------------
    
    . nlcom   (fem_educ : _b[fem_work:other_inc] / sqrt(2)) ///
    >                 (fem_educ : _b[fem_work:fem_educ] / sqrt(2)) ///
    >                 (kids : _b[fem_work:kids] / sqrt(2)) ///
    >                 (cons : _b[fem_work:_cons] / sqrt(2))
    
        fem_educ: _b[fem_work:other_inc] / sqrt(2)
        fem_educ: _b[fem_work:fem_educ] / sqrt(2)
            kids: _b[fem_work:kids] / sqrt(2)
            cons: _b[fem_work:_cons] / sqrt(2)
    
    ------------------------------------------------------------------------------
                 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
        fem_educ |  -.0542682   .0060749    -8.93   0.000    -.0661749   -.0423616
        fem_educ |   .1845729   .0300135     6.15   0.000     .1257475    .2433983
            kids |  -.1797433     .04754    -3.78   0.000    -.2729199   -.0865667
            cons |   .6821518   .4218658     1.62   0.106    -.1446899    1.508994
    ------------------------------------------------------------------------------

    Help would be immensely appreciated!

    Thank you,

    Lukas
    Last edited by Lukas Lang; 31 May 2023, 10:28.
    ------
    I use Stata 17

    Comment


    • #3
      I am sorry, I have been working on this for the last couple of days and I am now stuck.

      Anyone who can help with this?

      Or, anyone you know who can help with this?

      Many thanks,

      Lukas
      ------
      I use Stata 17

      Comment

      Working...
      X