Announcement

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

  • Extracting Output Matrix From ivreghdfe

    I'm trying to extract coefficients, standard errors and p-values from a a regression run with ivreghdfe. With the standard reghdfe, it's easy enough:

    Code:
     
     reghdfe price mpg weight, noabsorb
    (MWFE estimator converged in 1 iterations)
    
    HDFE Linear regression                            Number of obs   =         74
    Absorbing 1 HDFE group                            F(   2,     71) =      14.74
                                                      Prob > F        =     0.0000
                                                      R-squared       =     0.2934
                                                      Adj R-squared   =     0.2735
                                                      Within R-sq.    =     0.2934
                                                      Root MSE        =  2514.0286
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -49.51222   86.15604    -0.57   0.567    -221.3025     122.278
          weight |   1.746559   .6413538     2.72   0.008      .467736    3.025382
           _cons |   1946.069    3597.05     0.54   0.590    -5226.245    9118.382
    ------------------------------------------------------------------------------
    
    . mat OUTPUT = r(table)
    
    . mat li OUTPUT
    
    OUTPUT[9,3]
                   mpg      weight       _cons
         b  -49.512221   1.7465592   1946.0687
        se   86.156039   .64135379   3597.0496
         t  -.57468079   2.7232382   .54101802
    pvalue   .56732373   .00812981   .59018863
        ll  -221.30248   .46773602  -5226.2445
        ul   122.27804   3.0253823   9118.3819
        df          71          71          71
      crit   1.9939434   1.9939434   1.9939434
     eform           0           0           0

    But r(table) doesn't exist when using ivreghdfe. I think in part this is because ivreghdfe is a version of ivreg2. One can extract the first stage from ivreg2 like so:

    Code:
      
     sysuse auto ivreg2 price (mpg=weight), savefirst estimates replay _ivreg2_mpg mat l r(table)

    When replacing
    Code:
      estimates replay _ivreg2_mpg
    with
    Code:
      estimates replay _ivreg2_ price
    to get the first stage, stata tells me the _ivreg2_price is not found. Is there an easy way to extract model statistics from ivreg2 and ivreghdfe that I'm not seeing?

  • #2
    For -ivreg2, you can store and retrieve first- and second-stage results like this:

    Code:
    Code:
    sysuse auto, clear
    ivreg2 price (mpg=weight), savefirst
    est store stage2
    est dir
    
    *    You can replay either of the equations like this:
    est replay _ivreg2_mpg
    est replay stage2
    
    *    You can tabulate the two regression results like this
    est table _ivreg2_mpg stage2 , se 
    
    return list
    
    *    Estimates table has the added benefit of producing r(coef): 
    matlist r(coef)
    Results:
    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . ivreg2 price (mpg=weight), savefirst
    
    Stored estimation results
    -------------------------
    --------------------------------------------------------------------------
                 |           Dependent  Number of        
            Name | Command    variable     param.  Title 
    -------------+------------------------------------------------------------
     _ivreg2_mpg | ivreg2          mpg          2  First-stage regression: mpg
    --------------------------------------------------------------------------
    
    IV (2SLS) estimation
    --------------------
    
    Estimates efficient for homoskedasticity only
    Statistics consistent for homoskedasticity only
    
                                                          Number of obs =       74
                                                          F(  1,    72) =    25.48
                                                          Prob > F      =   0.0000
    Total (centered) SS     =  635065396.1                Centered R2   =   0.1801
    Total (uncentered) SS   =   3447834321                Uncentered R2 =   0.8490
    Residual SS             =  520685110.7                Root MSE      =     2653
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -340.1846   66.48161    -5.12   0.000    -470.4861    -209.883
           _cons |   13410.27   1449.068     9.25   0.000     10570.15    16250.39
    ------------------------------------------------------------------------------
    Underidentification test (Anderson canon. corr. LM statistic):          48.213
                                                       Chi-sq(1) P-val =    0.0000
    ------------------------------------------------------------------------------
    Weak identification test (Cragg-Donald Wald F statistic):              134.618
    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: weight
    ------------------------------------------------------------------------------
    
    . est store stage2
    
    . est dir
    
    --------------------------------------------------------------------------
                 |           Dependent  Number of        
            Name | Command    variable     param.  Title 
    -------------+------------------------------------------------------------
     _ivreg2_mpg | ivreg2          mpg          2  First-stage regression: mpg
          stage2 | ivreg2        price          2  IV (2SLS) estimation
    --------------------------------------------------------------------------
    
    . 
    . *       You can replay either of the equations like this:
    . est replay _ivreg2_mpg
    
    ------------------------------------------------------------------------------------------------------------------------
    Model _ivreg2_mpg (First-stage regression: mpg)
    ------------------------------------------------------------------------------------------------------------------------
    
    First-stage regression of mpg:
    
    Statistics consistent for homoskedasticity only
    Number of obs =                     74
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          weight |  -.0060087   .0005179   -11.60   0.000    -.0070411   -.0049763
           _cons |   39.44028   1.614003    24.44   0.000     36.22283    42.65774
    ------------------------------------------------------------------------------
    
    . est replay stage2
    
    ------------------------------------------------------------------------------------------------------------------------
    Model stage2
    ------------------------------------------------------------------------------------------------------------------------
    
    Stored estimation results
    -------------------------
    --------------------------------------------------------------------------
                 |           Dependent  Number of        
            Name | Command    variable     param.  Title 
    -------------+------------------------------------------------------------
     _ivreg2_mpg | ivreg2          mpg          2  First-stage regression: mpg
    --------------------------------------------------------------------------
    
    IV (2SLS) estimation
    --------------------
    
    Estimates efficient for homoskedasticity only
    Statistics consistent for homoskedasticity only
    
                                                          Number of obs =       74
                                                          F(  1,    72) =    25.48
                                                          Prob > F      =   0.0000
    Total (centered) SS     =  635065396.1                Centered R2   =   0.1801
    Total (uncentered) SS   =   3447834321                Uncentered R2 =   0.8490
    Residual SS             =  520685110.7                Root MSE      =     2653
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -340.1846   66.48161    -5.12   0.000    -470.4861    -209.883
           _cons |   13410.27   1449.068     9.25   0.000     10570.15    16250.39
    ------------------------------------------------------------------------------
    Underidentification test (Anderson canon. corr. LM statistic):          48.213
                                                       Chi-sq(1) P-val =    0.0000
    ------------------------------------------------------------------------------
    Weak identification test (Cragg-Donald Wald F statistic):              134.618
    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: weight
    ------------------------------------------------------------------------------
    
    . 
    . *       You can tabulate the two regression results like this
    . est table _ivreg2_mpg stage2 , se 
    
    ----------------------------------------
        Variable | _ivreg2_~g     stage2    
    -------------+--------------------------
          weight | -.00600869               
                 |  .00051788               
             mpg |              -340.18458  
                 |               66.481609  
           _cons |  39.440284    13410.269  
                 |  1.6140031    1449.0677  
    ----------------------------------------
                                Legend: b/se
    
    . 
    . return list
    
    macros:
                  r(names) : "_ivreg2_mpg stage2"
    
    matrices:
                   r(coef) :  3 x 4
    
    . 
    . *       Estimates table has the added benefit of producing r(coef): 
    . matlist r(coef)
    
                 | _ivreg2~g            | stage2               
                 |         b        var |         b        var 
    -------------+----------------------+----------------------
          weight | -.0060087   2.68e-07 |        .z         .z 
             mpg |        .z         .z | -340.1846   4419.804 
           _cons |  39.44028   2.605006 |  13410.27    2099797
    Does this help?

    Comment

    Working...
    X