/*The model is D=I(v+x'B+e>0), E(ez)=0, v=s'A+eta, eta density unknown,independent of e,s,x. s is union of regressors x and instruments z */ *.simpbin2 dv, bin() exog() very() * set trace on cap pro drop simpbin2 pro def simpbin2 version 8.0 local varlist "required existing min(2) max(2)" local if "optional " local options BIN(string) EXOG(string) VERY(string)" parse "`*'" preserve tokenize "`varlist'" di in g "Regression of `2' on `very'" qui reg `2' `very' tempvar eta predict `eta' if e(sample), resid qui sortedf1 `eta' /*generate sorted data density of V model error*/ local f `eta' zrnd `f' /* round near zero density away from zero*/ gen `1'star=(`1'-(`2'>=0))/`f' di in g " " di in g "Based on sorted data density of `1', f(`2'|.)" di in g " " di in g "`1'star is constructed as (`1'-(`2'>=0))/ f(`2'|.)" ivreg `1'star (`bin'=`exog'),robust drop `1'star di in g "Note the Std. Err. and Conf. Interval are wrong! " di " " di in g "Bootstrap command can be used to get correct Std Err. and Conf. Interval." di " " di in y `"Try it, :)) - bs "simpbin2 varlist" _b , size() level(), reps() saving() replace"' end