/************************ Robocall Study insheet2006.do file created: March 9, 2012 file updated: March 11, 2012 This program takes the 2011 csv files (which have had candidate names replaced with party names) turns them into .dta files, merges them together into one big .dta file, and calculates some basic variables, such as voter turnout. It is somewhat more compactly written than insheet2011.do (there is only a single loop and no separate code for the first file, but it does the same thing. *************************/ /********************** * 1. Inputs and settings **********************/ clear clear matrix set more off set matsize 2100 cd "C:\Users\Tom\Dropbox\robocalls\New\\" local path "C:\Users\Tom\Dropbox\robocalls\New\\" /**** Generate Random Variables ****/ * number of iterations local iter = 1000 set obs 306 gen temp = 0 gen temp2 = 0 gen order = _n set seed 0308 forvalues n = 1/`iter'{ sort order qui gen b`n' = floor(uniform()*279)+1 in 1/27 qui gen c`n' = 0 forvalues m=1/279 { qui replace temp = (b`n'==order[`m']) qui sum temp qui replace c`n' = `r(sum)' in `m' } qui replace c`n'=c`n'+1 qui gen v`n' = uniform() qui sort v`n' qui replace v`n' = 0 in 28/306 qui replace v`n' = 1 in 1/27 } sort order drop temp* drop b* save random.dta, replace /**** Format Data Appropriately ****/ use final_data_noc.dta, replace drop if year == 2008 keep id year pollid insample weights turnout lagturnout lagoppvoteshare robocall save final_data_noc_boot11.dta, replace use final_data_noc2006.dta, replace drop if year == 2006 keep id year pollid insample weights turnout lagturnout lagoppvoteshare robocall save final_data_noc_boot.dta, replace append using final_data_noc_boot11.dta drop if robocall == 1 drop robocall save final_data_noc_boot.dta, replace /**** Run Bootstrap ****/ use random.dta, replace mkmat c1-v`iter', matrix(R) use final_data_noc_boot.dta, replace gen dup = 0 mat define A = J(`iter',4,0) gen robocall = 0 egen district_id = group(id) gen iscopy = 0 gen test = 0 gen interact =0 forvalues n=1/`iter' { local counter = 280 forvalues m=1/279 { *disp(`n'*1000+`m') *disp R[2*(`n'-1)+1,`m'] if R[`m',2*(`n'-1)+1]>1 { local ncopy = R[`m',2*(`n'-1)+1] forvalues b= 2/`ncopy' { qui expand 2 if district_id == `m' & iscopy == 0, generate(newiscopy) qui replace test = test+newiscopy qui replace iscopy = newiscopy qui drop newiscopy qui gsort iscopy district_id qui replace district_id = `counter' if iscopy == 1 local counter = `counter' + 1 } } } forvalues m=1/306 { if R[`m',2*(`n'-1)+2]>0 { qui replace robocall = 1 if district_id == `m' } } replace interact = robocall*lagoppvoteshare qui areg turnout lagturnout lagoppvoteshare interact if(insample==1&year==2011) [fw = weights] , absorb(district_id) cluster(district_id) qui mat A[`n',1] = _b[interact] qui mat A[`n',2] = _se[interact] qui areg turnout lagturnout lagoppvoteshare interact if(insample==1&year==2008) [fw = weights] , absorb(district_id) cluster(district_id) qui mat A[`n',3] = _b[interact] qui mat A[`n',4] = _se[interact] qui drop if district_id > 279 replace robocall = 0 disp(`n') } /*** Get output ***/ mat list A