Announcement

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

  • Difficulty with margins: Wald estimate discrepency between ivreg2 and margins

    Hello,
    I am trying to estimate the Wald estimand and calculate standard errors using margins and suest, but I'm not able to exactly replicate what ivreg2 gets me or what I get by diving the reduced-form coefficient by the first-stage coefficient. Does anyone know why?

    ivreg2 is available from SSC. Documentation: http://www.repec.org/bocode/i/ivreg2.html

    (Note: the reason I'm using margins is: after I get this to work, I'm going to be simulating some other methods which will require margins, such as Edward Norton's (2022, NBER) guidance on calculating marginal effects on an outcome that has been transformed.)

    I simulate some data:

    Code:
      clearall
      set obs 50000
      set seed 10107
        * randomly draw instrument values, idiosyncratic terms for each individual
      drawnorm Z 
      replace Z=Z>0
      drawnorm U0
      drawnorm U1
        * set parameters which shift potential outcomes
      scalar mu1 = 1
      scalar mu0 = 0
        * Potential outcomes
      gen Y0 = mu0 + U0
      gen Y1 = mu1 + U1
      gen tx = Y1 - Y0 // treatment effect
      sum tx
        * Treatment decision
      * let Utility = Y + Z * 1[A=1]
      * ie, Z reflects additional inducement (or deterence, if negative) for taking treatment
      gen relativeutility1 = Y1 - Y0 + Z
      gen A = relativeutility1 > 0
      tab A, m
        * Outcome 
      gen Y = Y1*A + Y0*(1-A) 

    I estimate the local average treatment effect (LATE) using ivreg2:

    Code:
     ivreg2 Y (A=Z) , r
      gen insample=e(sample)==1
    I confirm by calculating Wald by hand:

    Code:
      reg Y Z if insample==1
      estimates store RF
      scalar coef_RF = _b[Z]
      reg A Z if insample==1
      estimates store FS
      scalar coef_FS = _b[Z]
      di coef_RF / coef_FS
    So far so good. But then I get a different point estimate and standard error when I use margins:


    Code:
      suest RF FS, vce(robust)
        margins if insample==1, dydx(Z) expression(predict(equation(RF_mean)) / predict(equation(FS_mean))) 

    I would greatly appreciate it if anyone has any idea why this last technique using margins doesn't yield the same estimate as ivreg2 or dividing the reduced-form coefficient by the first-stage coefficient. Thank You!

    Best,
    Nate

  • #2
    You are just taking a ratio of the coefficients, so the margins command should be:

    Code:
    clear all
      set obs 50000
      set seed 10107
        * randomly draw instrument values, idiosyncratic terms for each individual
      drawnorm Z 
      replace Z=Z>0
      drawnorm U0
      drawnorm U1
        * set parameters which shift potential outcomes
      scalar mu1 = 1
      scalar mu0 = 0
        * Potential outcomes
      gen Y0 = mu0 + U0
      gen Y1 = mu1 + U1
      gen tx = Y1 - Y0 // treatment effect
      sum tx
        * Treatment decision
      * let Utility = Y + Z * 1[A=1]
      * ie, Z reflects additional inducement (or deterence, if negative) for taking treatment
      gen relativeutility1 = Y1 - Y0 + Z
      gen A = relativeutility1 > 0
      tab A, m
        * Outcome 
      gen Y = Y1*A + Y0*(1-A) 
    
     ivreg2 Y (A=Z) , r
      gen insample=e(sample)==1
    
      reg Y Z if insample==1
      estimates store RF
      scalar coef_RF = _b[Z]
      reg A Z if insample==1
      estimates store FS
      scalar coef_FS = _b[Z]
      di coef_RF / coef_FS
    
    suest RF FS, vce(robust)
        margins if insample==1, expression( _b[RF_mean:Z] /  _b[FS_mean:Z]) 
    Res.:

    Code:
    .  ivreg2 Y (A=Z) , r
    
    IV (2SLS) estimation
    --------------------
    
    Estimates efficient for homoskedasticity only
    Statistics robust to heteroskedasticity
    
                                                          Number of obs =    50000
                                                          F(  1, 49998) =    62.61
                                                          Prob > F      =   0.0000
    Total (centered) SS     =  40274.30082                Centered R2   =  -0.0507
    Total (uncentered) SS   =  107867.0184                Uncentered R2 =   0.6077
    Residual SS             =  42315.00443                Root MSE      =    .9199
    
    ------------------------------------------------------------------------------
                 |               Robust
               Y |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
               A |   -.396867    .050154    -7.91   0.000    -.4951671   -.2985669
           _cons |   1.496244   .0423444    35.34   0.000      1.41325    1.579237
    ------------------------------------------------------------------------------
    Underidentification test (Kleibergen-Paap rk LM statistic):           2510.071
                                                       Chi-sq(1) P-val =    0.0000
    ------------------------------------------------------------------------------
    Weak identification test (Cragg-Donald Wald F statistic):             2641.615
                             (Kleibergen-Paap rk Wald F statistic):       2642.635
    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.
    NB: Critical values are for Cragg-Donald F statistic and i.i.d. errors.
    ------------------------------------------------------------------------------
    Hansen J statistic (overidentification test of all instruments):         0.000
                                                     (equation exactly identified)
    ------------------------------------------------------------------------------
    Instrumented:         A
    Excluded instruments: Z
    ------------------------------------------------------------------------------
    
    
    
    .     margins if insample==1, expression( _b[RF_mean:Z] /  _b[FS_mean:Z]) 
    Warning: expression() does not contain predict() or xb().
    Warning: prediction constant over observations.
    
    Predictive margins                              Number of obs     =     50,000
    Model VCE    : Robust
    
    Expression   : _b[RF_mean:Z] / _b[FS_mean:Z]
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _cons |   -.396867   .0501545    -7.91   0.000    -.4951681   -.2985659
    ------------------------------------------------------------------------------

    Comment


    • #3
      Thank you, Andrew Musau, I appreciate it ! I don't know why the other way didn't quite match up, but Andrew's solution does indeed match the other two methods!

      Comment

      Working...
      X