Announcement

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

  • save coefficients of interaction term

    Hi, I have a regression of the following form:

    Code:
     ivreg2 y (c.x##i.year = c.w##i.year) i.year
    Could someone please help me in creating a variable that stores the coefficient from this term? I'm running this regression in a loop for different y values so need to store each coefficient.

    Thanks!

  • #2
    I'm not quite sure precisely what you are looking for, but he output of help ivreg2 tells us that the command stores its coefficients in the Stata matrix e(b), so here is some example code for retrieving coefficients corresponding to those in the ivreg2 report. If you're not familiar with Stata matrix commands, start with the output of help matrix. If you're new to returned estimations, start with the output of help ereturn.
    Code:
    . use http://fmwww.bc.edu/ec-p/data/hayashi/griliches76.dta, clear
    (Wages of Very Young Men, Zvi Griliches, J.Pol.Ec. 1976)
    
    . ivreg2 lw s  i.year (c.s##i.year = c.rns##i.year)
    Warning - duplicate variables detected
    Duplicates:         s 67.year 68.year 69.year 70.year 71.year 73.year
    
    IV (2SLS) estimation
    --------------------
    
    Estimates efficient for homoskedasticity only
    Statistics consistent for homoskedasticity only
    
                                                          Number of obs =      758
                                                          F( 13,   744) =     9.39
                                                          Prob > F      =   0.0000
    Total (centered) SS     =  139.2861498                Centered R2   =  -1.1211
    Total (uncentered) SS   =  24652.24662                Uncentered R2 =   0.9880
    Residual SS             =  295.4456675                Root MSE      =    .6243
    
    ------------------------------------------------------------------------------
              lw |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
        year#c.s |
             67  |  -.4913112   1.540141    -0.32   0.750    -3.509933     2.52731
             68  |  -.3475382   .2634286    -1.32   0.187    -.8638487    .1687723
             69  |  -.1369025   .3759501    -0.36   0.716    -.8737511    .5999461
             70  |  -.6805452   .5553787    -1.23   0.220    -1.769067    .4079769
             71  |  -.7856451   .4655452    -1.69   0.091    -1.698097    .1268068
             73  |  -.5531592    .532216    -1.04   0.299    -1.596283     .489965
                 |
               s |   .4887797   .2391004     2.04   0.041     .0201516    .9574078
                 |
            year |
             67  |   5.849261   19.34329     0.30   0.762     -32.0629    43.76142
             68  |   4.112184   3.214649     1.28   0.201    -2.188412    10.41278
             69  |   1.387305   4.828885     0.29   0.774    -8.077135    10.85175
             70  |   8.878234   7.537416     1.18   0.239     -5.89483     23.6513
             71  |   10.40018   6.257345     1.66   0.096    -1.863987    22.66435
             73  |    7.39559    7.74392     0.96   0.340    -7.782214    22.57339
                 |
           _cons |  -.4039679   2.881636    -0.14   0.889    -6.051871    5.243936
    ------------------------------------------------------------------------------
    Underidentification test (Anderson canon. corr. LM statistic):           0.561
                                                       Chi-sq(2) P-val =    0.7555
    ------------------------------------------------------------------------------
    Weak identification test (Cragg-Donald Wald F statistic):                0.079
    Stock-Yogo weak ID test critical values:                       <not available>
    ------------------------------------------------------------------------------
    Sargan statistic (overidentification test of all instruments):           4.720
                                                       Chi-sq(1) P-val =    0.0298
    ------------------------------------------------------------------------------
    Instrumented:         67.year#c.s 68.year#c.s 69.year#c.s 70.year#c.s
                          71.year#c.s 73.year#c.s
    Included instruments: s 67.year 68.year 69.year 70.year 71.year 73.year
    Excluded instruments: rns 67.year#c.rns 68.year#c.rns 69.year#c.rns
                          70.year#c.rns 71.year#c.rns 73.year#c.rns
    Duplicates:           s 67.year 68.year 69.year 70.year 71.year 73.year
    ------------------------------------------------------------------------------
    
    .
    . matrix coeff = e(b)
    
    . matrix list coeff
    
    coeff[1,16]
          66b.year#    67.year#    68.year#    69.year#    70.year#    71.year#    73.year#
              co.s         c.s         c.s         c.s         c.s         c.s         c.s
    y1           0  -.49131124  -.34753817  -.13690248  -.68054523  -.78564513   -.5531592
    
                           66b.         67.         68.         69.         70.         71.
                 s        year        year        year        year        year        year
    y1   .48877974           0   5.8492611    4.112184   1.3873052   8.8782343   10.400184
    
                73.            
              year       _cons
    y1   7.3955899  -.40396787
    
    . display coeff[1,2]
    -.49131124
    
    . display coeff[1,colnumb(coeff,"67.year#c.s")]
    -.49131124
    Last edited by William Lisowski; 24 May 2019, 10:09.

    Comment

    Working...
    X