clear
set seed 1
set obs 10000
eststo clear
// Simulate data for IV regression
matrix input c = ( 1, .5, 0, .5\ ///
.5, 1, 0, 0\ ///
0, 0, 1, 0\ ///
.5, 0, 0, 1)
corr2data x u e z, corr(c)
// Calculate y
generate y = 1 + 2*x + 2*u + 5*e
// Without omitted variable bias
eststo: regress y x u
// With omitted variable bias
eststo: regress y x
// Reduced form
eststo: regress y z
local rf = _b[z]
// First stage
eststo: regress x z
local fs = _b[z]
predict xhat
predict xres, resid
// Two-stage predictor substitution (2SPS)
eststo: regress y xhat
// Two-stage residual inclusion (2SRI)
eststo: regress y x xres
// Two-stage least square (2SLS)
eststo: ivregress 2sls y (x = z)
// IV estimate = reduced form/first stage
di `rf'/`fs'
// Table
esttab, b(2) se(2) mtitle("DGP" "Bias" "Reduced form" "1st stage" "2SPS" "2SRI" "2SLS") ///
coeflabel(x "Predictor x" ///
z "Instrument z" ///
xres "1st stage residual" ///
_cons "Intercept") ///
rename(xhat x) drop(u) ///
stats(N, label(Observations) fmt(%9.0gc)) ///
title(Different varieties of instrumental variable regression) ///
varwidth(20)
Nov 25, 2019
Instrumental variable regression
Labels:
corr2data,
esttab,
ivregress,
matrix input
