// SELECTION RATIO APPROACH .DO FILE // // This file runs the selection ratio GMM estimator under the assumption of // parallel convergence. // // Set the values for your data in the parameters section below. // // The estimation and results sections then produce the following output: // // 1) GMM treatment effect estimate // // 2) GMM overidentification test // // 3) Test of selection on observables // // 4) Delta vs. k scatterplot by group // clear all set obs 5 gen parameter="" gen var="" gen t0=. gen t1=. gen t2=. gen t3=. gen t4=. save results.dta, replace // // PARAMETERS // local row=0 foreach var in lnemp lnearnbeg lnsep lnhira lnchurn { quietly forvalues outcome=0/4 { clear use mw_final * name of .dta file * ex: mw_final local d treat * name of treatment variable (must be binary) * ex: treat local x d_`var'_1418_tminus2 d_`var'_1418_tminus3 d_`var'_1418_tminus4 d_`var'_1418_tminus5 d_`var'_1418_tminus6 d_`var'_1418_tminus7 d_`var'_1418_tminus8 d_`var'_1418_tminus9 t1-t108 * list of observables used to measure similarity * ex: dlnteenprv1 dlnteenprv2 dlnteenprv3 dlnteenprv4 dlnteenprv5 dlnteenprv6 dlnteenprv7 dlnteenprv8 t1-t124 if `outcome'==0 { local y d_`var'_1418_t * outcome variable * ex: d_`var'_1418_tminus1_tplus4 * ex: d_`var'_1418_t } else { local y d_`var'_1418_tminus1_tplus`outcome' * outcome variable * ex: d_`var'_1418_tminus1_tplus4 * ex: d_`var'_1418_t } local groups gt1-gt6 * This should be a list of dummies for membership in the relevant comparisons. * So, treated observations and the first control group will have g1=1, while * all others will have g1=0. * * In the RDD case (treated and control groups approaching each other), g1 would * contain the closest treated and control observations, g2 would contain the * next closest, etc. * * It is also acceptable to write this as a hyphenated collection of variables, * e.g. g1-g5 * * ex: gt1-gt6 * ex: h2-h6 * ex: k3-k6 * * note: gt1-gt6 is the baseline analysis, h2-h6 is spillover-robust with one exclusion, * and k3-k6 is spillover-robust with two exclusions as used in the paper (i.e. * using all additional treated observations) local options ,winitial(identity) wmatrix(cluster time) * write any options for the GMM estimation here, as you would write them in a * normal Stata gmm command, making sure to start with a comma * ex: ,winitial(identity) wmatrix(cluster state) * ex: if natlawt==0 ,winitial(identity) wmatrix(cluster state) local restrictreg 0 * set this at 1 to estimate the coefficient b in w=xb from only observations * which belong to one of the groups you're using * set this to 0 to estimate b from all datapoints * ex: 0 // // ESTIMATION // gen useme=. lab var useme "Observation used in selection ratio estimation" quietly foreach g of varlist `groups' { replace useme=1 if `g'==1 } * figure out which observations are in at least one comparison replace useme=1-`restrictreg' if useme==. * only observations with useme=1 will be used in the following regression reg `y' `d' `x' if useme==1 predict yhat gen w=yhat-(`d'*_b[`d']) lab var w "Value of Xb in selection ratio first step" * w is the value of xb for each observation drop yhat * no longer needed drop if w==. drop if `y'==. local count=1 quietly foreach g of varlist `groups' { sum `d' if `g'==1 & w!=. gen dprob`count'=r(mean) gen drata`count'=1/dprob`count' gen dratb`count'=1/(1-dprob`count') local count=`count'+1 } * generate probability of treatment for each group local gmm local count=1 quietly foreach g of varlist `groups' { local gmm `gmm' (`g'*({ATT} + drata`count'*{sigma}*w*`d' - dratb`count'*{sigma}*w*(1-`d') - drata`count'*`y'*`d' + dratb`count'*(1-`d')*`y')) local count=`count'+1 } * writes out the text for the gmm commands gen k=. gen kse=. gen delta=. gen deltase=. gen graphme=. local obs=_N quietly foreach g of varlist `groups' { reg `y' `d' if `g'==1 replace delta=_b[`d'] if `g'==1 replace deltase=_se[`d'] if `g'==1 reg w `d' if `g'==1 replace k=_b[`d'] if `g'==1 replace kse=_se[`d'] if `g'==1 gsort +`g' -`d' replace graphme=1 in `obs' } * creates the estimates of delta and k by group // // RESULTS // dis "`gmm'" gmm `gmm' `options' * headline results local att=_b[/ATT] local att_se=_se[/ATT] local slope=_b[/sigma] local slope_se=_se[/sigma] estat overid * test of model local j_p=r(J_p) * now store the results: clear use results.dta local ticker=1 + `row' replace parameter="ATT" in `ticker' replace t`outcome'=`att' in `ticker' replace var="`var'" in `ticker' local ticker=`ticker'+1 replace parameter="ATT SE" in `ticker' replace t`outcome'=`att_se' in `ticker' replace var="`var'" in `ticker' local ticker=`ticker'+1 replace parameter="slope" in `ticker' replace t`outcome'=`slope' in `ticker' replace var="`var'" in `ticker' local ticker=`ticker'+1 replace parameter="slope SE" in `ticker' replace t`outcome'=`slope_se' in `ticker' replace var="`var'" in `ticker' local ticker=`ticker'+1 replace parameter="J-test p-val" in `ticker' replace t`outcome'=`j_p' in `ticker' replace var="`var'" in `ticker' save results.dta, replace } local row=`row' + 5 dis `row' local newrows=`row'+5 dis `newrows' set obs `newrows' save results.dta, replace }