******************************* ** Testing tsls.ado ** ******************************* ** Test 1: Basic XTIVREG2 ** ******************************* set more off clear use http://www.stata-press.com/data/r10/nlswork, replace set seed 12345 log using tsls_test,replace text timer clear rename ln_wage y1 rename wks_work y2 rename hours z1 rename ttl_exp x1 rename age x2 gen z2 = uniform() * 10 gen y3 = uniform() * 20 gen z3 = uniform() * 30 xtset idcode timer on 1 xtivreg2 y1 (y2 = z1) z3 x1 x2 , fe first cluster(idcode) timer off 1 preserve timer on 2 tsls y1 (y2 = z1) z3 x1 x2, demean fe(idcode) first cluster(idcode) replace timer off 2 timer on 3 tsls y1 (y2 = z1) z3 x1 x2, fe(idcode) first cluster(idcode) timer off 3 restore *************************************************** ** Test 2: XTIVREG2, Multiple Varaibles ** ************************************************** xtivreg2 y1 (y2 = z1) x1 x2 , fe tsls y1 (y2 = z1) x1 x2 , demean fe(idcode) ******************************* ** Test 3: Multiple IVs ** ******************************* xtivreg2 y1 (y2 = z1 z2) x1 x2 , fe tsls y1 (y2 = z1 z2) x1 x2 , demean fe(idcode) ************************************** ** Test 4: Multiple Endogenous ** ************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe tsls y1 (y2 y3 = z1 z2) x1 x2 , demean fe(idcode) ************************************** ** Test 5: Robust ** ************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe robust tsls y1 (y2 y3 = z1 z2) x1 x2 , demean fe(idcode) robust ************************************** ** Test 5: Cluster Robust ** ************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe robust cluster(idcode) tsls y1 (y2 y3 = z1 z2) x1 x2 , demean fe(idcode) robust cluster(idcode) ************************************** ** Test 5: Small Sample Errors ** ************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe small tsls y1 (y2 y3 = z1 z2) x1 x2 , demean fe(idcode) small ******************************************** ** Test 5: Robust Small Sample Errors ** ******************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe small robust tsls y1 (y2 y3 = z1 z2) x1 x2 , demean fe(idcode) small robust **************************************************** ** Test 5: Cluster Robust Small Sample Errors ** **************************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe small robust cluster(idcode) tsls y1 (y2 y3 = z1 z2) x1 x2 , demean fe(idcode) small robust cluster(idcode) **************************************************** ** Test 5: Areg ** **************************************************** xtivreg2 y1 (y2 = z1 ) , fe tsls y1 (y2 = z1 ) , fe(idcode) areg **************************************************** ** Test 5: Areg w/ Cluster ** **************************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe cluster(idcode) tsls y1 (y2 y3 = z1 z2) x1 x2 , fe(idcode) areg cluster(idcode) **************************************************** ** Test 5: Areg w/ Robust ** **************************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe robust tsls y1 (y2 y3 = z1 z2) x1 x2 , fe(idcode) areg robust **************************************************** ** Test 5: Areg w/ Cluster & Robust ** **************************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe robust cluster(idcode) tsls y1 (y2 y3 = z1 z2) x1 x2 , fe(idcode) areg robust cluster(idcode) **************************************************** ** Test 5: Areg w/ Small SEs ** **************************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe small tsls y1 (y2 y3 = z1 z2) x1 x2 , fe(idcode) areg small **************************************************** ** Test 5: Areg w/ Robust & Small SEs ** **************************************************** xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe robust small tsls y1 (y2 y3 = z1 z2) x1 x2 , fe(idcode) areg robust small **************************************************** ** Test 5: Areg w/ Cluster & Small SEs ** **************************************************** * The standard errors look off for this. xtivreg2 y1 (y2 y3 = z1 z2) x1 x2 , fe cluster(idcode) small tsls y1 (y2 y3 = z1 z2) x1 x2 , fe(idcode) areg cluster(idcode) small ********************************************** * Timing results ** * timer 1 - time for xtivreg2 ** * timer 2 - time for tsls ** * timer 3 - time for tsls with demeaned data** ********************************************** timer list