***Stata version 8 SE ***kta, December 4, 2003 **Be sure to file handles are updated to reflect the correct file folders log using "C:\individual randomization test monte carlo.log", replace **Create file that will hold chi-square results from simulations clear set mem 50m gen pers_chi_lin=. gen pers_df_lin=. gen phn_chi_lin=. gen phn_df_lin=. gen mail_chi_lin=. gen mail_df_lin=. gen pers_chi_int=. gen pers_df_int=. gen phn_chi_int=. gen phn_df_int=. gen mail_chi_int=. gen mail_df_int=. save "C:\chitest.dta", replace **Generate variables need in simulation in the household data files use "C:\NHrep_household.dta" gen filenum=. gen rand=. gen pers_sim=. gen phn_sim=. gen mail_sim=. gen pers_chi_lin=. gen pers_df_lin=. gen phn_chi_lin=. gen phn_df_lin=. gen mail_chi_lin=. gen mail_df_lin=. gen pers_chi_int=. gen pers_df_int=. gen phn_chi_int=. gen phn_df_int=. gen mail_chi_int=. gen mail_df_int=. gen V96_1=. gen V96_0=. gen MAJORPTY=. gen AGE=. gen AGEMISS=0 save "C:\NHrep_household.dta", replace **Begin simulation local i=1 while `i' <=100 { *Call up household data file and generate random assignments to mock personal contact, phone, and mail groups use "C:\NHrep_household.dta", clear replace rand=uniform() replace rand= rand*100 recode rand 0/37.19=1 37.19/46.49=2 46.49/71.65=3 71.65/77.66=4 77.66/80.39=5 80.39/81.02=6 81.02/96.14=7 96.14/100=8 replace pers_sim=rand replace phn_sim=rand replace mail_sim=rand recode pers_sim 2=1 4=1 6=1 8=1 *=0 recode phn_sim 5=1 6=1 7=1 8=1 *=0 recode mail_sim 3=1 4=1 7=1 8=1 *=0 *Construct individual level data file with these randomly generated assignments replace filenum=1 save "C:\HH1.dta", replace keep if PERSONS==2 replace filenum=2 append using "C:\Documents and Settings\Kevin Arceneaux\Postdoc\Matching\Imai Replication\HH1.dta" *Construct previous vote variable replace V96_1=V96_1_1 if filenum==1 replace V96_1=V96_2_1 if filenum==2 replace V96_0=V96_1_0 if filenum==1 replace V96_0=V96_2_0 if filenum==2 *Construct major party variable replace MAJORPTY=MAJPTY1 if filenum==1 replace MAJORPTY=MAJPTY2 if filenum==2 *construct age variable replace AGE=AGE1 if filenum==1 replace AGE=AGE2 if filenum==2 replace AGEMISS=1 if AGE==999 recode AGE 999=0 *Estimate additive linear randomization test models set more off xi: logit pers_sim PERSONS V96_0 V96_1 AGE AGEMISS MAJORPTY i.WARD local a=e(chi2) local b=e(df_m) xi: logit phn_sim PERSONS V96_0 V96_1 AGE AGEMISS MAJORPTY i.WARD local c=e(chi2) local d=e(df_m) xi: logit mail_sim PERSONS V96_0 V96_1 AGE AGEMISS MAJORPTY i.WARD local e=e(chi2) local f=e(df_m) *Estimate interactive randomization test models xi: logit pers_sim i.PERSONS*V96_0 i.PERSONS*V96_1 i.PERSONS*AGE i.PERSONS*AGEMISS i.PERSONS*MAJORPTY i.WARD*PERSONS i.V96_0*AGE i.V96_0*AGEMISS i.V96_0*MAJORPTY i.WARD*V96_0 i.V96_1*AGE i.V96_1*AGEMISS i.V96_1*MAJORPTY i.WARD*V96_1 i.MAJORPTY*AGE i.WARD*AGE i.MAJORPTY*AGEMISS i.WARD*AGEMISS local g=e(chi2) local h=e(df_m) xi: logit phn_sim i.PERSONS*V96_0 i.PERSONS*V96_1 i.PERSONS*AGE i.PERSONS*AGEMISS i.PERSONS*MAJORPTY i.WARD*PERSONS i.V96_0*AGE i.V96_0*AGEMISS i.V96_0*MAJORPTY i.WARD*V96_0 i.V96_1*AGE i.V96_1*AGEMISS i.V96_1*MAJORPTY i.WARD*V96_1 i.MAJORPTY*AGE i.WARD*AGE i.MAJORPTY*AGEMISS i.WARD*AGEMISS local j=e(chi2) local k=e(df_m) xi: logit mail_sim i.PERSONS*V96_0 i.PERSONS*V96_1 i.PERSONS*AGE i.PERSONS*AGEMISS i.PERSONS*MAJORPTY i.WARD*PERSONS i.V96_0*AGE i.V96_0*AGEMISS i.V96_0*MAJORPTY i.WARD*V96_0 i.V96_1*AGE i.V96_1*AGEMISS i.V96_1*MAJORPTY i.WARD*V96_1 i.MAJORPTY*AGE i.WARD*AGE i.MAJORPTY*AGEMISS i.WARD*AGEMISS local l=e(chi2) local m=e(df_m) *Save chi-sqare and degrees of freedom values from models replace pers_chi_lin=`a' in 1 replace pers_df_lin=`b' in 1 replace phn_chi_lin=`c' in 1 replace phn_df_lin=`d' in 1 replace mail_chi_lin=`e' in 1 replace mail_df_lin=`f' in 1 replace pers_chi_int=`g' in 1 replace pers_df_int=`h' in 1 replace phn_chi_int=`j' in 1 replace phn_df_int=`k' in 1 replace mail_chi_int=`l' in 1 replace mail_df_int=`m-' in 1 *Save to results file keep pers_chi_lin pers_df_lin phn_chi_lin phn_df_lin mail_chi_lin mail_df_lin pers_chi_int pers_df_int phn_chi_int phn_df_int mail_chi_int mail_df_int drop if pers_chi_lin==. append using "C:\chitest.dta" save "C:\chitest.dta", replace local i=`i'+1 } **Assess simulation results gen pers_lin_sig=0 gen phn_lin_sig=0 gen mail_lin_sig=0 gen pers_int_sig=0 gen phn_int_sig=0 gen mail_int_sig=0 sum pers_df_lin phn_df_lin mail_df_lin pers_df_int phn_df_int mail_df_int *For critical vaules see http://www.fourmilab.ch/rpkp/experiments/analysis/chiCalc.html replace pers_lin_sig=1 if pers_chi_lin>=48.602 /*0.05 level with 34 df*/ replace phn_lin_sig=1 if phn_chi_lin>=48.602 replace mail_lin_sig=1 if mail_chi_lin>=48.602 replace pers_int_sig=1 if pers_chi_int>=219.905 /*0.05 level with 187 df*/ replace phn_int_sig=1 if phn_chi_int>=219.905 replace mail_int_sig=1 if mail_chi_int>=219.905 tab pers_lin_sig tab phn_lin_sig tab mail_lin_sig tab pers_int_sig tab phn_int_sig tab mail_int_sig tab pers_lin_sig phn_lin_sig if mail_lin_sig==0 tab pers_lin_sig phn_lin_sig if mail_lin_sig==1 tab pers_int_sig phn_int_sig if mail_int_sig==0 tab pers_int_sig phn_int_sig if mail_int_sig==1 log close