Professional Documents
Culture Documents
clear all
set more off
use C:\Econometrics\Data\iv_health
* OLS regression
regress $y1list $y2list $x1list
* 2SLS estimation
ivregress 2sls $y1list ($y2list = $x2list) $x1list, first
* Weak instruments
* Correlations of endogenous regressors with instruments
correlate $y2list $x2listalt
* Systems of equations
* 2SLS estimation
reg3 ($y1list $y2list $x1list $x2list)($y2list $y1list $x1list2 $x2list2), 2sls
* 3SLS estimation
reg3 ($y1list $y2list $x1list $x2list)($y2list $y1list $x1list2 $x2list2)
. * Instrumental Variables in Stata
. * Copyright 2013 by Ani Katchova
.
. clear all
.
. use C:\Econometrics\Data\iv_health
.
. * Define dependent variable y1, endogenous variable y2
. * Define exogenous variables x1 and instrumental variables x2
. * Define alternative set of instruments x2alt for overidentified case
. * Define exogenous variables x12 for eq2, instrumental variable x22 for eq2
. global y1list logmedexpense
.
. describe $y1list $y2list $x1list $x2list
.
. * OLS regression
. regress $y1list $y2list $x1list
------------------------------------------------------------------------------
logmedexpe~e | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
healthinsu | .0749595 .0260124 2.88 0.004 .02397 .125949
illnesses | .440653 .0095721 46.04 0.000 .4218897 .4594162
age | -.0025946 .001879 -1.38 0.167 -.0062777 .0010886
logincome | .0172363 .0137865 1.25 0.211 -.009788 .0442607
_cons | 5.780127 .150891 38.31 0.000 5.48435 6.075903
------------------------------------------------------------------------------
.
. * 2SLS estimation
. ivregress 2sls $y1list ($y2list = $x2list) $x1list, first
First-stage regressions
-----------------------
------------------------------------------------------------------------------
healthinsu | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
illnesses | .011351 .0036336 3.12 0.002 .0042285 .0184736
age | -.0085302 .0007125 -11.97 0.000 -.0099268 -.0071337
logincome | .0544246 .0056429 9.64 0.000 .0433634 .0654858
ssiratio | -.1997539 .0141579 -14.11 0.000 -.2275062 -.1720017
_cons | .9591576 .0568776 16.86 0.000 .8476662 1.070649
------------------------------------------------------------------------------
------------------------------------------------------------------------------
logmedexpe~e | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
healthinsu | -.852201 .1983369 -4.30 0.000 -1.240934 -.4634679
illnesses | .4485123 .0102903 43.59 0.000 .4283437 .4686808
age | -.0117975 .0027882 -4.23 0.000 -.0172622 -.0063327
logincome | .0976929 .0224588 4.35 0.000 .0536744 .1417113
_cons | 6.589839 .2346179 28.09 0.000 6.129996 7.049681
------------------------------------------------------------------------------
Instrumented: healthinsu
Instruments: illnesses age logincome ssiratio
.
. * 2SLS estimation - overidentified
. ivregress 2sls $y1list ($y2list = $x2listalt) $x1list, first
First-stage regressions
-----------------------
------------------------------------------------------------------------------
healthinsu | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
illnesses | .0117912 .0036286 3.25 0.001 .0046785 .0189039
age | -.0079491 .0007184 -11.06 0.000 -.0093573 -.0065409
logincome | .0509146 .0056665 8.99 0.000 .039807 .0620221
ssiratio | -.1909688 .0142168 -13.43 0.000 -.2188365 -.163101
firmlocation | .1156546 .0200232 5.78 0.000 .0764051 .1549041
_cons | .9124637 .0573591 15.91 0.000 .8000285 1.024899
------------------------------------------------------------------------------
------------------------------------------------------------------------------
logmedexpe~e | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
healthinsu | -.9696236 .1863391 -5.20 0.000 -1.334841 -.6044057
illnesses | .4495077 .0104242 43.12 0.000 .4290766 .4699387
age | -.012963 .002727 -4.75 0.000 -.0183079 -.0076181
logincome | .1078825 .0218155 4.95 0.000 .0651249 .1506401
_cons | 6.692387 .2286487 29.27 0.000 6.244244 7.14053
------------------------------------------------------------------------------
Instrumented: healthinsu
Instruments: illnesses age logincome ssiratio firmlocation
.
. * 2SLS estimation (details)
. regress $y2list $x2list $x1list
------------------------------------------------------------------------------
healthinsu | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
ssiratio | -.1997539 .0141579 -14.11 0.000 -.2275062 -.1720017
illnesses | .011351 .0036336 3.12 0.002 .0042285 .0184736
age | -.0085302 .0007125 -11.97 0.000 -.0099268 -.0071337
logincome | .0544246 .0056429 9.64 0.000 .0433634 .0654858
_cons | .9591576 .0568776 16.86 0.000 .8476662 1.070649
------------------------------------------------------------------------------
. predict y2hat, xb
------------------------------------------------------------------------------
logmedexpe~e | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
y2hat | -.8522011 .1868427 -4.56 0.000 -1.21845 -.4859521
illnesses | .4485123 .0096939 46.27 0.000 .4295103 .4675143
age | -.0117975 .0026266 -4.49 0.000 -.0169461 -.0066488
logincome | .0976929 .0211572 4.62 0.000 .0562204 .1391653
_cons | 6.589839 .2210212 29.82 0.000 6.156593 7.023084
------------------------------------------------------------------------------
.
. * Durbin-Wu-Hausman test of endogeneity
. quietly ivregress 2sls $y1list ($y2list = $x2list) $x1list, first
. estat endogenous
Tests of endogeneity
Ho: variables are exogenous
.
. quietly regress $y2list $x2list $x1list
. test v1hat
( 1) v1hat = 0
F( 1, 10083) = 25.14
Prob > F = 0.0000
.
. * Test of overidentifying restrictions
. quietly ivregress gmm $y1list ($y2list = $x2listalt) $x1list, wmatrix(robust)
. estat overid
.
. * IV estimation with binary endogenous regressor (first step is probit model)
. treatreg $y1list $x1list, treat($y2list = $x2list $x1list)
-------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
--------------+----------------------------------------------------------------
logmedexpense |
illnesses | .4533646 .0110531 41.02 0.000 .4317009 .4750284
age | -.0174793 .002292 -7.63 0.000 -.0219716 -.012987
logincome | .1473667 .0171907 8.57 0.000 .1136736 .1810599
healthinsu | -1.42463 .0812462 -17.53 0.000 -1.58387 -1.265391
_cons | 7.089755 .1860256 38.11 0.000 6.725152 7.454359
--------------+----------------------------------------------------------------
healthinsu |
ssiratio | -.4833678 .0343442 -14.07 0.000 -.5506812 -.4160545
illnesses | .0346595 .0099313 3.49 0.000 .0151946 .0541245
age | -.0237617 .0019748 -12.03 0.000 -.0276323 -.0198912
logincome | .152461 .0148235 10.29 0.000 .1234075 .1815145
_cons | 1.243892 .1568575 7.93 0.000 .9364568 1.551327
--------------+----------------------------------------------------------------
/athrho | .7859563 .0436984 17.99 0.000 .7003089 .8716036
/lnsigma | .3552498 .015163 23.43 0.000 .3255307 .3849688
--------------+----------------------------------------------------------------
rho | .6561122 .024887 .6045638 .702188
sigma | 1.426537 .0216306 1.384765 1.469568
lambda | .9359682 .0485072 .8408959 1.031041
-------------------------------------------------------------------------------
LR test of indep. eqns. (rho = 0): chi2(1) = 90.32 Prob > chi2 = 0.0000
.
.
. * Weak instruments
. * Correlations of endogenous regressors with instruments
. correlate $y2list $x2listalt
(obs=10089)
.
. * Weak instrument tests - just-identified model
. quietly ivregress 2sls $y1list ($y2list = $x2list) $x1list, vce(robust)
.
. * Weak instrument tests - two or more overidentifying restrictions
. quietly ivregress gmm $y1list ($y2list = $x2listalt) $x1list, vce(robust)
. estat firststage, forcenonrobust
.
.
. * Systems of equations
.
. * 2SLS estimation
. reg3 ($y1list $y2list $x1list $x2list)($y2list $y1list $x1list2 $x2list2), 2sls
-------------------------------------------------------------------------------
| Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------+----------------------------------------------------------------
logmedexpense |
healthinsu | -1.6725 .5499929 -3.04 0.002 -2.750531 -.5944692
illnesses | .4578235 .0131069 34.93 0.000 .432133 .4835141
age | -.0187948 .0052074 -3.61 0.000 -.0290017 -.0085879
logincome | .1423373 .0348757 4.08 0.000 .0739781 .2106966
ssiratio | -.163858 .1186859 -1.38 0.167 -.396492 .068776
_cons | 7.376635 .5575224 13.23 0.000 6.283846 8.469424
--------------+----------------------------------------------------------------
healthinsu |
logmedexpense | .2348304 .0820282 2.86 0.004 .0740484 .3956123
illnesses | -.0995706 .036138 -2.76 0.006 -.170404 -.0287371
firmlocation | .2828365 .0269203 10.51 0.000 .2300705 .3356025
_cons | -.9720765 .4658588 -2.09 0.037 -1.885198 -.0589552
-------------------------------------------------------------------------------
Endogenous variables: logmedexpense healthinsu
Exogenous variables: illnesses age logincome ssiratio firmlocation
------------------------------------------------------------------------------
.
. * 3SLS estimation
. reg3 ($y1list $y2list $x1list $x2list)($y2list $y1list $x1list2 $x2list2)
-------------------------------------------------------------------------------
| Coef. Std. Err. z P>|z| [95% Conf. Interval]
--------------+----------------------------------------------------------------
logmedexpense |
healthinsu | -1.599042 .5498181 -2.91 0.004 -2.676666 -.5214188
illnesses | .4563656 .0131028 34.83 0.000 .4306845 .4820466
age | -.0177463 .0052054 -3.41 0.001 -.0279487 -.0075439
logincome | .1359816 .0348627 3.90 0.000 .067652 .2043113
ssiratio | -.1339564 .1186419 -1.13 0.259 -.3664902 .0985774
_cons | 7.273976 .5573174 13.05 0.000 6.181654 8.366298
--------------+----------------------------------------------------------------
healthinsu |
logmedexpense | .2348304 .0820119 2.86 0.004 .0740899 .3955708
illnesses | -.0995706 .0361308 -2.76 0.006 -.1703857 -.0287554
firmlocation | .2828365 .026915 10.51 0.000 .2300841 .3355888
_cons | -.9720765 .4657664 -2.09 0.037 -1.884962 -.0591911
-------------------------------------------------------------------------------
Endogenous variables: logmedexpense healthinsu
Exogenous variables: illnesses age logincome ssiratio firmlocation
------------------------------------------------------------------------------