** ** STATA COMMAND: edvreg 1.1 ** ** Implements two-stage estimators described in ** ** Jeffrey Lewis, "Estimating Regression Models ** in which the Dependent Variable Is Based on Estimates..." ** Unpublished working paper, 2000. ** ** SYNTAX: edvreg , dvste() [prop] [cluster(var)] [hc3] ** where, ** varlist = list of variables as in the reg command. ** varname = standard errors of the dependent variable. ** prop = Option tells Stata that is proportional, ** rather than equal, to the SE of the dependent variable. ** ** ** (C) Jeffrey B Lewis (jblewis@Princeton.edu), August 2000 ** ** ** Published as Lewis, J.B. & Linzer, D.A. ** "Estimating Regression Models in Which the Dependent ** Variable Is Based on Estimates" Political Analysis, 2005 ** ** 4/10/2007 - cluster standard errors allowed. ** ** 08/25/2006 ** small correction by Eduardo Leoni ** (trace was being substracted instead of ** added in the sigmasq formula) ** added borjas weights. Eduardo Leoni used in ** ** Borjas, G.J. & Sueyoshi, G.T. A two-stage estimator for probit models with structural group effects Journal of Econometrics, 1994, 64, 165-182 ** **and ** **Huber, J.D.; Kernell, G. & Leoni, E.L. Institutional Context, ** Cognitive Resources and Party Attachments Across Democracies ** Political Analysis, 2005, 13, 365-386 ** program define edvreg version 6.0 tempvar svar dvv varCorr syntax varlist [if] [in], Dvste(string) [Prop] [borjas] [cluster(varlist)] [hc3] [Level(integer 95)] local indvars "`varlist'" if "`cluster'"~="" { local cluster="cluster(`cluster')" } gettoken depvar indvars : indvars qui gen `dvv' = `dvste'*`dvste' `if'`in' disp disp in green "Sampled dependent variable regression" disp if ("`prop'" == "") { qui gen `svar' = sum(`dvv') local swsq = `svar'[_N] qui reg `depvar' `indvars' `if'`in', level(`level') `cluster' `hc3' local dof = e(df_r) local sumsr = `dof'*e(rmse)*e(rmse) qui matrix accum XpX = `indvars' `if' `in' qui matrix accum XpGX = `indvars' [iw=`dvv'] `if' `in' matrix tr = trace(inv(XpX)*XpGX) *following line modified by E. leoni local sigma2 = (`sumsr'-`swsq') / `dof' if ("`borjas'"=="") { /* apply hanushek weights */ local sigma2 = (`sumsr'-`swsq'+tr[1,1]) / `dof' } if (`sigma2' < 0) {local sigma2 = 0} disp in green "Estimated Sigma = " in yellow %7.5f sqrt(`sigma2') disp in green "Mean Omega2 = " in yellow %7.5f sqrt(`swsq'/`dof') qui gen `varCorr' = (1/(`sigma2'+`dvv')) `if'`in' /* gen w=1/(`varCorr') */ regress `depvar' `indvars' `if'`in' [aw=`varCorr'], `cluster' `hc3' level(`level') } else { tempvar e v qui reg `depvar' `indvars' `if'`in', level(`level') `cluster' `hc3' predict `e' if e(sample), resid replace `e' = `e'*`e' qui reg `e' `dvv' `if'`in', level(`level') `cluster' `hc3' if (_b[_cons]>0) { disp in green "Coeff. on variance from sampling = " _continue disp in yellow %7.4f _b[`dvv'] " (" %7.4f _se[`dvv'] ")" disp in green " Estimated variance of epsilon = " _continue disp in yellow %7.4f _b[_cons] " (" %7.4f _se[_cons] ")" } else { qui reg `e' `dvv' `if'`in', nocons level(`level') `cluster' `hc3' disp in green "Coeff. on variance from sampling = " _continue disp in yellow %7.4f _b[`dvv'] " (" %7.4f _se[`dvv'] ")" disp in green " Variance of epsilon = " _continue disp in yellow %7.4f 0 in blue " (constraint imposed)" } predict `v' if e(sample) regress `depvar' `indvars' `if'`in' [aw=1/`v'], `cluster' `hc3' level(`level') } end