Announcement

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

  • Potential bug in ivreg2?

    In ivreg2 the option "savesfirst" is supposed to "save the first-stage and reduced form estimations as a single estimated system." But it seems to be doing something else:

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . qui ivreg2 price (mpg = trunk), savesfirst
    
    . estimates replay _ivreg2_sfirst_price
    
    ---------------------------------------------------------------------------------------
    Model _ivreg2_sfirst_price (System of first-stage/reduced form regressions)
    ---------------------------------------------------------------------------------------
    
    System of first-stage/reduced-form regressions:
    -----------------------------------------------
    
    Statistics consistent for homoskedasticity only
    Number of obs =                     74
    ------------------------------------------------------------------------------
                 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    price        |
           trunk |   216.7482   77.14554     2.81   0.006     62.96142     370.535
           _cons |   3183.504   1110.728     2.87   0.005     969.3088    5397.699
    -------------+----------------------------------------------------------------
    mpg          |
           trunk |  -.7866364   .1296715    -6.07   0.000    -1.045132   -.5281411
           _cons |   32.11886   1.866987    17.20   0.000     28.39709    35.84063
    ------------------------------------------------------------------------------
    
    . reg price trunk
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =      7.89
           Model |  62747229.9         1  62747229.9   Prob > F        =    0.0064
        Residual |   572318166        72  7948863.42   R-squared       =    0.0988
    -------------+----------------------------------   Adj R-squared   =    0.0863
           Total |   635065396        73  8699525.97   Root MSE        =    2819.4
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           trunk |   216.7482   77.14554     2.81   0.006     62.96142     370.535
           _cons |   3183.504   1110.728     2.87   0.005     969.3088    5397.699
    ------------------------------------------------------------------------------
    As we can see, savesfirst does not seem to save the estimates from the reduced-form (second stage) regression but only those of an alternative regression of "price" on "trunk". Is this correct, or did I make a mistake somewhere? More importantly, is there a way to store both the first and second stage estimates together? Maybe in some other package? Many thanks!

    (This is related to this thread: https://www.statalist.org/forums/for...cients-in-2sls)

  • #2
    ivreg2 is from SSC, as you are asked to explain in FAQ Advice # 12. I cannot think of situations where you would simultaneously need the first- and second-stage results. If it is a matter of exporting these to a table, see https://www.statalist.org/forums/for...eg2-by-outreg2. I do not know what ivreg2 promises, but you can write to the authors if you think that it does not do what it claims. A way to combine models is through Ben Jann's program mergemodels. I do not think he posted this to SSC (or published it in SJ), so I present the do-file below combined with your example.

    Code:
    capt prog drop mergemodels
    prog mergemodels, eclass
     version 8
     syntax namelist
     tempname b V tmp
     foreach name of local namelist {
       qui est restore `name'
       mat `b' = nullmat(`b') , e(b)
       mat `b' = `b'[1,1..colsof(`b')-1]
       mat `tmp' = e(V)
       mat `tmp' = `tmp'[1..rowsof(`tmp')-1,1..colsof(`tmp')-1]
       capt confirm matrix `V'
       if _rc {
         mat `V' = `tmp'
       }
       else {
         mat `V' = ///
          ( `V' , J(rowsof(`V'),colsof(`tmp'),0) ) \ ///
          ( J(rowsof(`tmp'),colsof(`V'),0) , `tmp' )
       }
     }
     local names: colfullnames `b'
     mat coln `V' = `names'
     mat rown `V' = `names'
     eret post `b' `V'
     eret local cmd "ivreg2"
    end
    
    sysuse auto, clear
    eststo m1: qui ivreg2 price (mpg = trunk), savesfirst
    mergemodels  _ivreg2_sfirst_price m1
    est sto wanted
    est restore wanted
    cap noi est replay wanted
    
    di _b[price: trunk]
    di _b[mpg: trunk]
    di []_b[mpg]
    lincom  _b[price: trunk] + []_b[mpg]
    Res.:

    Code:
    . cap noi est replay wanted
    
    ---------------------------------------------------------------------------------------------------
    Model wanted
    ---------------------------------------------------------------------------------------------------
    
                                                          Number of obs =        .
                                                          F(  .,     .) =        .
                                                          Prob > F      =        .
    Total (centered) SS     =            .                Centered R2   =        .
    Total (uncentered) SS   =            .                Uncentered R2 =        .
    Residual SS             =            .                Root MSE      =        .
    
    ------------------------------------------------------------------------------
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    price        |
           trunk |   216.7482   77.14554     2.81   0.005     65.54576    367.9507
           _cons |   3183.504   1110.728     2.87   0.004     1006.518     5360.49
    -------------+----------------------------------------------------------------
    mpg          |
           trunk |  -.7866364   .1296715    -6.07   0.000    -1.040788    -.532485
    -------------+----------------------------------------------------------------
             mpg |   -275.538   90.31788    -3.05   0.002    -452.5578   -98.51819
    ------------------------------------------------------------------------------
    type mismatch
    
    .
    . di _b[price: trunk]
    216.74823
    
    . di _b[mpg: trunk]
    -.78663645
    
    . di []_b[mpg]
    -275.53799
    
    . lincom  _b[price: trunk] + []_b[mpg]
    
     ( 1)  [price]trunk + mpg = 0
    
    ------------------------------------------------------------------------------
                 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             (1) |  -58.78977   118.7803    -0.49   0.621    -291.5948    174.0153
    ------------------------------------------------------------------------------
    Last edited by Andrew Musau; 11 Nov 2020, 23:12.

    Comment


    • #3
      When I issue the command:
      Code:
      ivreg2 price (mpg = trunk), savesfirst
      I get the following output:
      Code:
      Stored estimation results
      -------------------------
      ---------------------------------------------------------------------------------------------
              name | command      depvar       npar  title
      -------------+-------------------------------------------------------------------------------
      _ivreg2_sf~e | ivreg2       no depvar       4  System of first-stage/reduced form regressions
      ---------------------------------------------------------------------------------------------
      
      IV (2SLS) estimation
      --------------------
      
      Estimates efficient for homoskedasticity only
      Statistics consistent for homoskedasticity only
      
                                                            Number of obs =       74
                                                            F(  1,    72) =     9.06
                                                            Prob > F      =   0.0036
      Total (centered) SS     =  635065396.1                Centered R2   =   0.2144
      Total (uncentered) SS   =   3447834321                Uncentered R2 =   0.8553
      Residual SS             =  498896894.9                Root MSE      =     2597
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               mpg |   -275.538   90.31788    -3.05   0.002    -452.5578   -98.51819
             _cons |   12033.47   1947.065     6.18   0.000     8217.294    15849.65
      ------------------------------------------------------------------------------
      Underidentification test (Anderson canon. corr. LM statistic):          25.030
                                                         Chi-sq(1) P-val =    0.0000
      ------------------------------------------------------------------------------
      Weak identification test (Cragg-Donald Wald F statistic):               36.801
      Stock-Yogo weak ID test critical values: 10% maximal IV size             16.38
                                               15% maximal IV size              8.96
                                               20% maximal IV size              6.66
                                               25% maximal IV size              5.53
      Source: Stock-Yogo (2005).  Reproduced by permission.
      ------------------------------------------------------------------------------
      Sargan statistic (overidentification test of all instruments):           0.000
                                                       (equation exactly identified)
      ------------------------------------------------------------------------------
      Instrumented:         mpg
      Excluded instruments: trunk
      ------------------------------------------------------------------------------
      The stored results are:
      Code:
      . estimates replay _ivreg2_sfirst_price
      
      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      Model _ivreg2_sfirst_price (System of first-stage/reduced form regressions)
      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      
      System of first-stage/reduced-form regressions:
      -----------------------------------------------
      
      Statistics consistent for homoskedasticity only
      Number of obs =                     74
      ------------------------------------------------------------------------------
                   |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      price        |
             trunk |   216.7482   77.14554     2.81   0.006     62.96142     370.535
             _cons |   3183.504   1110.728     2.87   0.005     969.3088    5397.699
      -------------+----------------------------------------------------------------
      mpg          |
             trunk |  -.7866364   .1296715    -6.07   0.000    -1.045132   -.5281411
             _cons |   32.11886   1.866987    17.20   0.000     28.39709    35.84063
      ------------------------------------------------------------------------------
      This is the reduced form because the two endogenous variables are price and mpg, and the only (excluded) exogenous variable is trunk.
      The second equation in the reduced form is the first stage regression.
      There are various save.. options in ivreg2.
      Last edited by Eric de Souza; 12 Nov 2020, 02:56.

      Comment


      • #4
        Andrew Musau
        Using lincom after mergemodels is dangerous. The reported lincom standard errors in this case ignore the covariance between the estimators for the different equations.
        https://www.kripfganz.de/stata/

        Comment


        • #5
          Yes, these are set to zero for independent models. In this case, probably only the coefficient makes sense.

          Comment


          • #6
            Andrew Musau Thanks for your help. I am estimating a structural model and one of the parameter is a combination of the first and second stage coefficients. Unfortunately, I do need the covariance between the estimators of the two equations to estimate that parameter.

            Comment


            • #7
              Hi Mathieu,
              Have you considered using the command eregress?

              Code:
              sysuse auto, clear
              eregress price , endogenous(mpg =trunk)
              This produces the VCOV matrix for all coefficients for the first and second stage of the regression.
              Fernando

              Comment


              • #8
                FernandoRios That works! Thank you!

                Comment

                Working...
                X