Chapter 21 - Estimating Average Treatment Effects

Examples

------------------------------------------------------------------------------------------
      name:  SN
       log:  \iiexample21.smcl
  log type:  smcl
 opened on:  13 May 2020, 16:33:13
. **********************************************
.  * Solomon Negash - Examples
.  * Wooldridge (2010). Economic Analysis of Cross-Section and Panel Data. 2nd ed.  
.  * STATA Program, version 16.1. 

.  * Chapter 21  - Estimating Average Treatment Effects
.  ********************************************

. // Example 21.1 (Causal Effects of Job Training on Earnings, cont'd)

.  * Table 21.1 Column 2 & 3

.  bcuse jtrain2, clear nodesc

.  eststo DiM2: reg re78 train, r

Linear regression                               Number of obs     =        445
                                                F(1, 443)         =       7.15
                                                Prob > F          =     0.0078
                                                R-squared         =     0.0178
                                                Root MSE          =     6.5795

------------------------------------------------------------------------------
             |               Robust
        re78 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       train |   1.794343   .6708247     2.67   0.008     .4759489    3.112737
       _cons |   4.554802   .3402038    13.39   0.000     3.886188    5.223416
------------------------------------------------------------------------------

.  eststo PRA2: reg re78 train age educ black hisp married re74 re75, r

Linear regression                               Number of obs     =        445
                                                F(8, 436)         =       3.00
                                                Prob > F          =     0.0028
                                                R-squared         =     0.0548
                                                Root MSE          =      6.506

------------------------------------------------------------------------------
             |               Robust
        re78 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       train |   1.682588   .6580774     2.56   0.011     .3891892    2.975986
         age |   .0557707   .0397936     1.40   0.162    -.0224405    .1339819
        educ |   .4058834   .1567272     2.59   0.010     .0978486    .7139182
       black |  -2.169781   1.008415    -2.15   0.032    -4.151741   -.1878214
        hisp |   .1579258   1.366293     0.12   0.908    -2.527414    2.843266
     married |  -.1402712   .8706551    -0.16   0.872    -1.851474    1.570932
        re74 |   .0828563   .1073171     0.77   0.440     -.128067    .2937795
        re75 |   .0515333   .1247684     0.41   0.680     -.193689    .2967557
       _cons |   .6217388   2.384255     0.26   0.794    -4.064324    5.307802
------------------------------------------------------------------------------

.  logit train age educ black hisp married re74 re75, nolog 

Logistic regression                             Number of obs     =        445
                                                LR chi2(7)        =       8.58
                                                Prob > chi2       =     0.2840
Log likelihood = -297.80826                     Pseudo R2         =     0.0142

------------------------------------------------------------------------------
       train |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         age |   .0107155    .014017     0.76   0.445    -.0167572    .0381882
        educ |   .0628366   .0558026     1.13   0.260    -.0465346    .1722077
       black |  -.3553063   .3577202    -0.99   0.321    -1.056425    .3458123
        hisp |  -.9322569   .5001292    -1.86   0.062    -1.912492    .0479784
     married |   .1440193   .2734583     0.53   0.598    -.3919492    .6799878
        re74 |  -.0221324   .0252097    -0.88   0.380    -.0715425    .0272777
        re75 |   .0459029   .0429705     1.07   0.285    -.0383177    .1301235
       _cons |  -.9237055   .7693924    -1.20   0.230    -2.431687    .5842759
------------------------------------------------------------------------------

.  predict yhat
(option pr assumed; Pr(train))

.  g uhat = train -yhat

.  g ate = uhat*re78/(yhat*(1-yhat))

.  reg ate, r nohead 
------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   1.627364   .8438395     1.93   0.054    -.0310517     3.28578
------------------------------------------------------------------------------

.  reg ate if yhat<=.9 & yhat>=.1, r nohead 
------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   1.627364   .8438395     1.93   0.054    -.0310517     3.28578
------------------------------------------------------------------------------

.  reg ate if yhat<=.95 & yhat>=.05

      Source |       SS           df       MS      Number of obs   =       445
-------------+----------------------------------   F(0, 444)       =      0.00
       Model |           0         0           .   Prob > F        =         .
    Residual |  140689.832       444   316.86899   R-squared       =    0.0000
-------------+----------------------------------   Adj R-squared   =    0.0000
       Total |  140689.832       444   316.86899   Root MSE        =    17.801

------------------------------------------------------------------------------
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   1.627364   .8438395     1.93   0.054    -.0310517     3.28578
------------------------------------------------------------------------------

.  foreach x of var age educ black hisp married re74 re75{ 
  .    gen u`x'= uhat*`x'
  .   }

.  eststo PSW2: reg ate uage ueduc ublack uhisp umarried ure74 ure75, r

Linear regression                               Number of obs     =        445
                                                F(7, 437)         =      34.42
                                                Prob > F          =     0.0000
                                                R-squared         =     0.4150
                                                Root MSE          =     13.723

------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        uage |   .3910961   .1634717     2.39   0.017     .0698076    .7123846
       ueduc |   1.734985   .4210857     4.12   0.000     .9073805     2.56259
      ublack |  -7.214304   3.700214    -1.95   0.052    -14.48673    .0581244
       uhisp |   7.359991   8.469947     0.87   0.385    -9.286906    24.00689
    umarried |  -1.038132   3.765855    -0.28   0.783    -8.439571    6.363306
       ure74 |   .2628723   .6204462     0.42   0.672    -.9565572    1.482302
       ure75 |   .1593004   .5991879     0.27   0.790    -1.018348    1.336949
       _cons |   1.627364   .6505422     2.50   0.013     .3487838    2.905944
------------------------------------------------------------------------------





.  * Table 21.1 Column 4 & 5
.  bcuse jtrain3, clear nodesc

.  eststo DiM3: reg re78 train, r

Linear regression                               Number of obs     =      2,675
                                                F(1, 2673)        =     537.36
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0609
                                                Root MSE          =     15.152

------------------------------------------------------------------------------
             |               Robust
        re78 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       train |  -15.20478   .6559143   -23.18   0.000    -16.49093   -13.91863
       _cons |   21.55392    .311785    69.13   0.000     20.94256    22.16529
------------------------------------------------------------------------------

.  eststo PRA3: reg re78 train age educ black hisp married re74 re75, r

Linear regression                               Number of obs     =      2,675
                                                F(8, 2666)        =     253.07
                                                Prob > F          =     0.0000
                                                R-squared         =     0.5863
                                                Root MSE          =      10.07

------------------------------------------------------------------------------
             |               Robust
        re78 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       train |   .8597703   .7665736     1.12   0.262    -.6433687    2.362909
         age |   -.081537    .020672    -3.94   0.000    -.1220718   -.0410022
        educ |   .5280233    .088394     5.97   0.000     .3546957     .701351
       black |  -.5427091   .4421585    -1.23   0.220    -1.409717    .3242993
        hisp |   2.165568   1.218258     1.78   0.076    -.2232582    4.554394
     married |   1.220271    .496305     2.46   0.014     .2470896    2.193453
        re74 |   .2778865   .0617851     4.50   0.000      .156735     .399038
        re75 |   .5681222   .0665303     8.54   0.000     .4376661    .6985784
       _cons |   .7767343   1.485113     0.52   0.601    -2.135356    3.688824
------------------------------------------------------------------------------


.  logit train age educ black hisp married re74 re75, nolog  

Logistic regression                             Number of obs     =      2,675
                                                LR chi2(7)        =     872.82
                                                Prob > chi2       =     0.0000
Log likelihood = -236.23799                     Pseudo R2         =     0.6488

------------------------------------------------------------------------------
       train |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         age |  -.0840291    .014761    -5.69   0.000    -.1129601    -.055098
        educ |  -.0624764   .0513973    -1.22   0.224    -.1632134    .0382605
       black |   2.242955   .3176941     7.06   0.000     1.620286    2.865624
        hisp |   2.094338   .5584561     3.75   0.000     .9997841    3.188892
     married |  -1.588358   .2602448    -6.10   0.000    -2.098428   -1.078287
        re74 |   -.117043   .0293604    -3.99   0.000    -.1745882   -.0594977
        re75 |  -.2577589   .0394991    -6.53   0.000    -.3351758   -.1803421
       _cons |   2.302714   .9112559     2.53   0.012     .5166853    4.088743
------------------------------------------------------------------------------
Note: 158 failures and 0 successes completely determined.

.  predict yhat
(option pr assumed; Pr(train))

.  g uhat = train -yhat

.  g ate = uhat*re78/(yhat*(1-yhat))

.  reg ate, r nohead 
------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   11.02854   19.17591     0.58   0.565    -26.57258    48.62966
------------------------------------------------------------------------------

.  reg ate if yhat<=.9 & yhat>=.1, r nohead 
------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   1.024012   1.116107     0.92   0.360    -1.172147     3.22017
------------------------------------------------------------------------------

.  reg ate if yhat<=.95 & yhat>=.05

      Source |       SS           df       MS      Number of obs   =       422
-------------+----------------------------------   F(0, 421)       =      0.00
       Model |           0         0           .   Prob > F        =         .
    Residual |  195052.966       421  463.308708   R-squared       =    0.0000
-------------+----------------------------------   Adj R-squared   =    0.0000
       Total |  195052.966       421  463.308708   Root MSE        =    21.525

------------------------------------------------------------------------------
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |  -.1989809   1.047801    -0.19   0.849    -2.258555    1.860593
------------------------------------------------------------------------------

.  foreach x of var age educ black hisp married re74 re75{ 
  .    gen u`x'= uhat*`x'
  .   }

.  eststo PSW3: reg ate uage ueduc ublack uhisp umarried ure74 ure75, r

Linear regression                               Number of obs     =      2,675
                                                F(7, 2667)        =       1.19
                                                Prob > F          =     0.3042
                                                R-squared         =     0.4822
                                                Root MSE          =     714.59

------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        uage |  -24.32996   28.92733    -0.84   0.400    -81.05223    32.39231
       ueduc |  -24.78431   74.25584    -0.33   0.739    -170.3892    120.8205
      ublack |   -1353.41   781.8495    -1.73   0.084    -2886.503    179.6824
       uhisp |  -2497.521   1281.549    -1.95   0.051    -5010.452    15.40991
    umarried |   1659.848   983.3841     1.69   0.092    -268.4247    3588.121
       ure74 |   431.6481   333.6441     1.29   0.196    -222.5792    1085.875
       ure75 |   315.1882    281.238     1.12   0.263    -236.2785    866.6548
       _cons |   11.02855   13.81648     0.80   0.425    -16.06355    38.12064
------------------------------------------------------------------------------



.  * Table 21.1 Column 6 & 7
.  bcuse jtrain3, clear nodesc

.  g rebar = (re74 + re75)/2 

.  keep if rebar <= 15.0 
(1,513 observations deleted)

.  eststo DiM3s: reg re78 train, r

Linear regression                               Number of obs     =      1,162
                                                F(1, 1160)        =      58.05
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0312
                                                Root MSE          =     10.101

------------------------------------------------------------------------------
             |               Robust
        re78 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       train |  -5.005321   .6569703    -7.62   0.000    -6.294304   -3.716338
       _cons |    11.1906   .3349949    33.41   0.000     10.53334    11.84787
------------------------------------------------------------------------------

.  eststo PRA3s: reg re78 train age educ black hisp married re74 re75, r

Linear regression                               Number of obs     =      1,162
                                                F(8, 1153)        =      82.43
                                                Prob > F          =     0.0000
                                                R-squared         =     0.2797
                                                Root MSE          =     8.7365

------------------------------------------------------------------------------
             |               Robust
        re78 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       train |   2.059039   .8011361     2.57   0.010     .4871915    3.630887
         age |  -.1016697   .0238413    -4.26   0.000    -.1484468   -.0548925
        educ |   .4046894    .099396     4.07   0.000     .2096721    .5997068
       black |  -1.226412   .5942647    -2.06   0.039    -2.392374   -.0604508
        hisp |   .2360508   .9030373     0.26   0.794     -1.53573    2.007831
     married |   1.841522   .5986858     3.08   0.002     .6668861    3.016157
        re74 |   .2466141   .0857127     2.88   0.004     .0784438    .4147844
        re75 |   .6600326   .0819874     8.05   0.000     .4991713    .8208939
       _cons |   2.100924   1.639151     1.28   0.200     -1.11513    5.316978
------------------------------------------------------------------------------

.  logit train age educ black hisp married re74 re75, nolog 

Logistic regression                             Number of obs     =      1,162
                                                LR chi2(7)        =     601.16
                                                Prob > chi2       =     0.0000
Log likelihood = -200.38544                     Pseudo R2         =     0.6000

------------------------------------------------------------------------------
       train |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         age |  -.0967819   .0161755    -5.98   0.000    -.1284853   -.0650784
        educ |  -.0757067   .0551246    -1.37   0.170    -.1837489    .0323355
       black |   2.245799   .3363927     6.68   0.000     1.586481    2.905117
        hisp |   2.251116   .6025146     3.74   0.000     1.070209    3.432023
     married |  -1.687559   .2830233    -5.96   0.000    -2.242274   -1.132843
        re74 |  -.1736866   .0362111    -4.80   0.000     -.244659   -.1027142
        re75 |  -.3189529   .0505282    -6.31   0.000    -.4179863   -.2199194
       _cons |   3.091271   .9883031     3.13   0.002     1.154233     5.02831
------------------------------------------------------------------------------

.  predict yhat
(option pr assumed; Pr(train))

.  g uhat = train -yhat

.  g ate = uhat*re78/(yhat*(1-yhat))

.  reg ate, r nohead 
------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |    7.04867   14.69166     0.48   0.631     -21.7765    35.87384
------------------------------------------------------------------------------

.  reg ate if yhat<=.9 & yhat>=.1, r nohead 
------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   1.923516    1.35118     1.42   0.156    -.7374268     4.58446
------------------------------------------------------------------------------

.  reg ate if yhat<=.95 & yhat>=.05

      Source |       SS           df       MS      Number of obs   =       380
-------------+----------------------------------   F(0, 379)       =      0.00
       Model |           0         0           .   Prob > F        =         .
    Residual |  171073.277       379  451.380678   R-squared       =    0.0000
-------------+----------------------------------   Adj R-squared   =    0.0000
       Total |  171073.277       379  451.380678   Root MSE        =    21.246

------------------------------------------------------------------------------
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       _cons |   .9467866   1.089883     0.87   0.386    -1.196187     3.08976
------------------------------------------------------------------------------

.  foreach x of var age educ black hisp married re74 re75{ 
  .    gen u`x'= uhat*`x'
  .   }

.  eststo PSW3s: reg ate uage ueduc ublack uhisp umarried ure74 ure75, r

Linear regression                               Number of obs     =      1,162
                                                F(7, 1154)        =       0.38
                                                Prob > F          =     0.9171
                                                R-squared         =     0.3591
                                                Root MSE          =     402.16

------------------------------------------------------------------------------
             |               Robust
         ate |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        uage |   24.64698   17.66033     1.40   0.163    -10.00298    59.29693
       ueduc |  -110.8254   79.11365    -1.40   0.162    -266.0481    44.39734
      ublack |  -446.0219   350.4072    -1.27   0.203    -1133.528    241.4845
       uhisp |  -1152.845   914.6663    -1.26   0.208     -2947.44    641.7507
    umarried |   728.6138   533.9536     1.36   0.173    -319.0148    1776.242
       ure74 |   70.85153   56.16707     1.26   0.207    -39.34948    181.0525
       ure75 |   354.0008    229.487     1.54   0.123    -96.25769    804.2594
       _cons |    7.04867   11.79754     0.60   0.550    -16.09836     30.1957
------------------------------------------------------------------------------

.  estout DiM2 DiM3 DiM3s PRA2 PRA3 PRA3s, stats(N, fmt(%9.0g) labels("Sample size"))/*
>         */ keep(train) cells(b(nostar fmt(3)) se(par fmt(3))) /* 
>         */  ti("Table 21.2 (Difference in means and Pooled regression adj.)") 

Table 21.2 (Difference in means and Pooled regression adj.)
------------------------------------------------------------------------------------------
                     DiM2         DiM3        DiM3s         PRA2         PRA3        PRA3s
                     b/se         b/se         b/se         b/se         b/se         b/se
------------------------------------------------------------------------------------------
train               1.794      -15.205       -5.005        1.683        0.860        2.059
                  (0.671)      (0.656)      (0.657)      (0.658)      (0.767)      (0.801)
------------------------------------------------------------------------------------------
Sample size           445         2675         1162          445         2675         1162
------------------------------------------------------------------------------------------

.  estout PSW2 PSW3 PSW3s, stats(N, fmt(%9.0g) labels("Sample size"))/*
>         */ keep(_cons) cells(b(nostar fmt(3)) se(par fmt(3))) ti("Table 21.1 (Propensity score) ")
>  

Table 21.1 (Propensity score) 
---------------------------------------------------
                     PSW2         PSW3        PSW3s
                     b/se         b/se         b/se
---------------------------------------------------
_cons               1.627       11.029        7.049
                  (0.651)     (13.816)     (11.798)
---------------------------------------------------
Sample size           445         2675         1162
---------------------------------------------------

.  est clear





. // Example 21.2 (Causal Effect of Job Training on Earnings)

.  bcuse jtrain2, clear nodesc

.  eststo mATE2: nnmatch re78 train age educ black hisp marr re74 re75

Matching estimator:  Average Treatment Effect 

Weighting matrix: inverse variance          Number of obs          =       445
                                            Number of matches  (m) =         1

------------------------------------------------------------------------------
        re78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        SATE |   1.627792    .772682     2.11   0.035     .1133632    3.142221
------------------------------------------------------------------------------
Matching variables:  age educ black hisp married re74 re75

.  eststo mATT2: nnmatch re78 train age educ black hisp marr re74 re75,  tc(att)

Matching estimator:  Average Treatment Effect for the Treated

Weighting matrix: inverse variance          Number of obs          =       445
                                            Number of matches  (m) =         1

------------------------------------------------------------------------------
        re78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        SATT |   1.823749   .8819327     2.07   0.039     .0951925    3.552305
------------------------------------------------------------------------------
Matching variables:  age educ black hisp married re74 re75


.  bcuse jtrain3, clear nodesc

.  eststo mATE3: nnmatch re78 train age educ black hisp marr re74 re75

Matching estimator:  Average Treatment Effect 

Weighting matrix: inverse variance          Number of obs          =      2675
                                            Number of matches  (m) =         1

------------------------------------------------------------------------------
        re78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        SATE |  -12.86929    3.81465    -3.37   0.001    -20.34586   -5.392711
------------------------------------------------------------------------------
Matching variables:  age educ black hisp married re74 re75

.  eststo mATT3: nnmatch re78 train age educ black hisp marr re74 re75,  tc(att)

Matching estimator:  Average Treatment Effect for the Treated

Weighting matrix: inverse variance          Number of obs          =      2675
                                            Number of matches  (m) =         1

------------------------------------------------------------------------------
        re78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        SATT |   .1548273    1.47817     0.10   0.917    -2.742333    3.051988
------------------------------------------------------------------------------
Matching variables:  age educ black hisp married re74 re75

.  g rebar = (re74 + re75)/2 

.  keep if rebar <= 15.0 
(1,513 observations deleted)

.  eststo mATE3s: nnmatch re78 train age educ black hisp marr re74 re75

Matching estimator:  Average Treatment Effect 

Weighting matrix: inverse variance          Number of obs          =      1162
                                            Number of matches  (m) =         1

------------------------------------------------------------------------------
        re78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        SATE |  -3.846288   2.495099    -1.54   0.123    -8.736593    1.044017
------------------------------------------------------------------------------
Matching variables:  age educ black hisp married re74 re75

.  eststo mATT3s: nnmatch re78 train age educ black hisp marr re74 re75,  tc(att)

Matching estimator:  Average Treatment Effect for the Treated

Weighting matrix: inverse variance          Number of obs          =      1162
                                            Number of matches  (m) =         1

------------------------------------------------------------------------------
        re78 |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        SATT |  -.2323443   1.648832    -0.14   0.888    -3.463996    2.999307
------------------------------------------------------------------------------
Matching variables:  age educ black hisp married re74 re75

.  estout mATE2 mATT2 mATE3 mATT3 mATE3s mATT3s, stats(N, fmt(%9.0g) labels("Sample size"))/*
>         */ cells(b(nostar fmt(3)) se(par fmt(3))) ti("Table 21.2") 

Table 21.2
------------------------------------------------------------------------------------------
                    mATE2        mATT2        mATE3        mATT3       mATE3s       mATT3s
                     b/se         b/se         b/se         b/se         b/se         b/se
------------------------------------------------------------------------------------------
SATE                1.628                   -12.869                    -3.846             
                  (0.773)                   (3.815)                   (2.495)             
SATT                             1.824                     0.155                    -0.232
                               (0.882)                   (1.478)                   (1.649)
------------------------------------------------------------------------------------------
Sample size           445          445         2675         2675         1162         1162
------------------------------------------------------------------------------------------

.  est clear 




. // Example 21.3 (Estimating the Effects of Education on Fertility)

. bcuse fertil2, clear nodesc

. g w=0

. replace w=1 if educ>=7
(2,423 real changes made)

. reg children w age agesq evermarr urban electric tv

      Source |       SS           df       MS      Number of obs   =     4,358
-------------+----------------------------------   F(7, 4350)      =    880.03
       Model |  12607.4006         7  1801.05723   Prob > F        =    0.0000
    Residual |  8902.63153     4,350  2.04658196   R-squared       =    0.5861
-------------+----------------------------------   Adj R-squared   =    0.5855
       Total |  21510.0321     4,357  4.93689055   Root MSE        =    1.4306

------------------------------------------------------------------------------
    children |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           w |  -.3935524   .0495534    -7.94   0.000    -.4907024   -.2964025
         age |   .2719307   .0171033    15.90   0.000     .2383996    .3054618
       agesq |   -.001896   .0002752    -6.89   0.000    -.0024356   -.0013564
    evermarr |   .6947417   .0523984    13.26   0.000     .5920142    .7974691
       urban |  -.2437082   .0460252    -5.30   0.000     -.333941   -.1534753
    electric |   -.336644   .0754557    -4.46   0.000    -.4845756   -.1887124
          tv |  -.3259749   .0897716    -3.63   0.000     -.501973   -.1499767
       _cons |  -3.526605   .2451026   -14.39   0.000    -4.007131   -3.046079
------------------------------------------------------------------------------

. ivreg children (w=frsthalf) age agesq evermarr urban electric tv 

Instrumental variables (2SLS) regression

      Source |       SS           df       MS      Number of obs   =     4,358
-------------+----------------------------------   F(7, 4350)      =    829.33
       Model |  12154.5373         7  1736.36247   Prob > F        =    0.0000
    Residual |  9355.49483     4,350  2.15068847   R-squared       =    0.5651
-------------+----------------------------------   Adj R-squared   =    0.5644
       Total |  21510.0321     4,357  4.93689055   Root MSE        =    1.4665

------------------------------------------------------------------------------
    children |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           w |   -1.13068   .6192352    -1.83   0.068    -2.344696    .0833367
         age |   .2627018     .01916    13.71   0.000     .2251385    .3002651
       agesq |  -.0019787   .0002905    -6.81   0.000    -.0025483   -.0014091
    evermarr |   .6167576   .0845468     7.29   0.000     .4510028    .7825123
       urban |  -.1672413   .0795281    -2.10   0.036    -.3231569   -.0113257
    electric |  -.2343255   .1154192    -2.03   0.042     -.460606   -.0080451
          tv |  -.1371643   .1829146    -0.75   0.453    -.4957701    .2214415
       _cons |   -2.83005   .6350035    -4.46   0.000     -4.07498    -1.58512
------------------------------------------------------------------------------
Instrumented:  w
Instruments:   age agesq evermarr urban electric tv frsthalf
------------------------------------------------------------------------------

. probit w frsthalf age agesq evermarr urban electric tv, nolog  

Probit regression                               Number of obs     =      4,358
                                                LR chi2(7)        =    1130.84
                                                Prob > chi2       =     0.0000
Log likelihood =  -2428.384                     Pseudo R2         =     0.1889

------------------------------------------------------------------------------
           w |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    frsthalf |  -.2206627   .0418563    -5.27   0.000    -.3026995   -.1386259
         age |  -.0150337   .0174845    -0.86   0.390    -.0493027    .0192354
       agesq |  -.0007325   .0002897    -2.53   0.011    -.0013003   -.0001647
    evermarr |  -.2972879   .0486734    -6.11   0.000     -.392686   -.2018898
       urban |   .2998122   .0432321     6.93   0.000     .2150789    .3845456
    electric |   .4246668   .0751255     5.65   0.000     .2774235      .57191
          tv |   .9281707   .0977462     9.50   0.000     .7365915     1.11975
       _cons |    1.13537   .2440057     4.65   0.000     .6571273    1.613612
------------------------------------------------------------------------------

. predict what
(option pr assumed; Pr(w))
(3 missing values generated)

. ivreg children (w=what) age agesq evermarr urban electric tv

Instrumental variables (2SLS) regression

      Source |       SS           df       MS      Number of obs   =     4,358
-------------+----------------------------------   F(7, 4350)      =    710.92
       Model |  10524.2445         7  1503.46351   Prob > F        =    0.0000
    Residual |  10985.7876     4,350  2.52546841   R-squared       =    0.4893
-------------+----------------------------------   Adj R-squared   =    0.4884
       Total |  21510.0321     4,357  4.93689055   Root MSE        =    1.5892

------------------------------------------------------------------------------
    children |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           w |  -1.974509    .331779    -5.95   0.000    -2.624964   -1.324053
         age |    .252137   .0194358    12.97   0.000     .2140329     .290241
       agesq |  -.0020734   .0003079    -6.73   0.000    -.0026772   -.0014697
    evermarr |    .527485   .0677212     7.79   0.000     .3947169    .6602531
       urban |  -.0797056   .0613673    -1.30   0.194    -.2000168    .0406056
    electric |  -.1171961   .0953328    -1.23   0.219    -.3040969    .0697047
          tv |   .0789773   .1302613     0.61   0.544    -.1764013    .3343558
       _cons |  -2.032667   .4119708    -4.93   0.000    -2.840339   -1.224994
------------------------------------------------------------------------------
Instrumented:  w
Instruments:   age agesq evermarr urban electric tv what
------------------------------------------------------------------------------

. ivreg children (w=what) age agesq evermarr urban electric tv, r 

Instrumental variables (2SLS) regression        Number of obs     =      4,358
                                                F(7, 4350)        =     678.11
                                                Prob > F          =     0.0000
                                                R-squared         =     0.4893
                                                Root MSE          =     1.5892

------------------------------------------------------------------------------
             |               Robust
    children |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
           w |  -1.974509   .3135566    -6.30   0.000    -2.589239   -1.359778
         age |    .252137   .0210049    12.00   0.000     .2109566    .2933173
       agesq |  -.0020734   .0003816    -5.43   0.000    -.0028215   -.0013254
    evermarr |    .527485   .0695789     7.58   0.000      .391075     .663895
       urban |  -.0797056   .0605259    -1.32   0.188    -.1983672     .038956
    electric |  -.1171961   .0891859    -1.31   0.189    -.2920458    .0576536
          tv |   .0789773   .1084846     0.73   0.467    -.1337078    .2916623
       _cons |  -2.032667   .3642986    -5.58   0.000    -2.746877   -1.318456
------------------------------------------------------------------------------
Instrumented:  w
Instruments:   age agesq evermarr urban electric tv what
------------------------------------------------------------------------------

.  log close 

      name:  SN
       log:  iiexample21.smcl
  log type:  smcl
 closed on:  13 May 2020, 16:33:52
------------------------------------------------------------------------------------------