/************************ Robocall Study merge2006.do file created: March 10, 2012 file updated: March 12, 2012 This program takes the raw data from 2008 and 2006 and merges them into a final dataset (without campaign spending). It also generates a riding-level dataset for 2008 (final_data_spending_test.dta) for the robustness test with campaing spending. Finally, it generates the panel dataset for 2011, 2008, 2006 I use for the time trend estimations. *************************/ /********************** * 1. Inputs and settings **********************/ clear set more off set memory 800m /* Set directories: */ *local path "/User/Anke/Documents/data/elections/" cd "/Users/Anke/Documents/Dropbox/robocalls/New/" *local path "/Users/Anke/Documents/Dropbox/New/" *cd "C:\Users\Tom\Dropbox\robocalls\New\\" *local path "C:\Users\Tom\Dropbox\robocalls\New\\" *cd "D:\Users\Tom\Desktop\\" *local path "D:\Users\Tom\Desktop\\" /* Logs: */ capture log close capture log using merge2006.txt, text replace /*Upload master data*/ tempfile lags2008 tempfile master2008 use 2008\master_data2008.dta, replace append using 2006\master_data2006.dta gen prov = trunc(id/1000) replace pollnum = "1000" if missing(pollnum) /*** Robocall identifiers ****/ gen robocall = 0 label variable robocall "indicator of whether riding affected by robocall in 2011 or not" label define robocalll 1"yes" 0 "no" label value robocall robocalll split name, parse("/") drop name2 sort year name1 replace robocall = 1 if (name1=="Sydney--Victoria" | name1=="Kitchener--Waterloo" | name1=="London North Centre" | name1=="London West" | name1=="Mississauga East--Cooksville" | name1=="Niagara Falls" | name1=="Oakville" | name1=="Ottawa West--Nepean" | name1=="Parkdale--High Park" | name1=="Perth--Wellington" | name1=="Egmont" | name1=="Simcoe--Grey" | name1=="St. Catharines" | name1=="Sudbury" | name1=="Wellington--Halton Hills" | name1=="Willowdale" | name1=="Saint Boniface" | name1=="Winnipeg South Centre" | name1=="Eglinton--Lawrence" | name1=="Etobicoke Centre" | name1=="Guelph" | name1=="Cambridge" | name1=="Hamilton East--Stoney Creek" | name1=="Haldimand--Norfolk" | name1=="Kitchener--Conestoga") replace robocall = 1 if id == 35063 replace robocall = 1 if name1 =="St. Paul's" replace robocall = 1 if id == 35011 replace robocall = 1 if id == 46014 replace robocall = 1 if id == 35019 replace robocall = 1 if id == 11003 replace robocall = 1 if id == 35022 replace robocall = 1 if id == 35027 replace robocall = 1 if id == 35028 replace robocall = 1 if id == 35032 replace robocall = 1 if id == 35038 replace robocall = 1 if id == 35039 replace robocall = 1 if id == 35043 replace robocall = 1 if id == 35044 replace robocall = 1 if id == 35048 replace robocall = 1 if id == 35054 replace robocall = 1 if id == 35060 replace robocall = 1 if id == 35066 replace robocall = 1 if id == 35063 replace robocall = 1 if id == 35068 replace robocall = 1 if id == 35070 replace robocall = 1 if id == 46009 replace robocall = 1 if id == 35085 replace robocall = 1 if id == 35076 replace robocall = 1 if id == 35077 replace robocall = 1 if id == 35088 replace robocall = 1 if id == 12010 replace robocall = 1 if id == 35098 replace robocall = 1 if id == 35100 /*** extended list ****/ gen robcall_ext = 0 replace robcall_ext = 1 if id == 35008 replace robcall_ext = 1 if id == 59002 replace robcall_ext = 1 if id == 35011 replace robcall_ext = 1 if id == 59005 replace robcall_ext = 1 if id == 35015 replace robcall_ext = 1 if id == 35016 replace robcall_ext = 1 if id == 48012 replace robcall_ext = 1 if id == 48013 replace robcall_ext = 1 if id == 35019 replace robcall_ext = 1 if id == 11003 replace robcall_ext = 1 if id == 46005 replace robcall_ext = 1 if id == 59008 replace robcall_ext = 1 if id == 35021 replace robcall_ext = 1 if id == 35022 replace robcall_ext = 1 if id == 13003 replace robcall_ext = 1 if id == 35027 replace robcall_ext = 1 if id == 35028 replace robcall_ext = 1 if id == 35030 replace robcall_ext = 1 if id == 35031 replace robcall_ext = 1 if id == 59011 replace robcall_ext = 1 if id == 35036 replace robcall_ext = 1 if id == 35037 replace robcall_ext = 1 if id == 35039 replace robcall_ext = 1 if id == 35038 replace robcall_ext = 1 if id == 24027 replace robcall_ext = 1 if id == 35040 replace robcall_ext = 1 if id == 35043 replace robcall_ext = 1 if id == 35044 replace robcall_ext = 1 if id == 35045 replace robcall_ext = 1 if id == 35048 replace robcall_ext = 1 if id == 35051 replace robcall_ext = 1 if id == 24044 replace robcall_ext = 1 if id == 59014 replace robcall_ext = 1 if id == 35057 replace robcall_ext = 1 if id == 59019 replace robcall_ext = 1 if id == 35059 replace robcall_ext = 1 if id == 35060 replace robcall_ext = 1 if id == 35062 replace robcall_ext = 1 if id == 35063 replace robcall_ext = 1 if id == 35066 replace robcall_ext = 1 if id == 35068 replace robcall_ext = 1 if id == 35070 replace robcall_ext = 1 if id == 35071 replace robcall_ext = 1 if id == 24049 replace robcall_ext = 1 if id == 59007 replace robcall_ext = 1 if id == 59022 replace robcall_ext = 1 if id == 47007 replace robcall_ext = 1 if id == 59024 replace robcall_ext = 1 if id == 46009 replace robcall_ext = 1 if id == 13009 replace robcall_ext = 1 if id == 35078 replace robcall_ext = 1 if id == 35079 replace robcall_ext = 1 if id == 35084 replace robcall_ext = 1 if id == 35085 replace robcall_ext = 1 if id == 12009 replace robcall_ext = 1 if id == 35076 replace robcall_ext = 1 if id == 35077 replace robcall_ext = 1 if id == 35088 replace robcall_ext = 1 if id == 12010 replace robcall_ext = 1 if id == 35090 replace robcall_ext = 1 if id == 59030 replace robcall_ext = 1 if id == 59031 replace robcall_ext = 1 if id == 59032 replace robcall_ext = 1 if id == 59033 replace robcall_ext = 1 if id == 35034 replace robcall_ext = 1 if id == 47013 replace robcall_ext = 1 if id == 12011 replace robcall_ext = 1 if id == 35100 replace robcall_ext = 1 if id == 35102 replace robcall_ext = 1 if id == 35101 replace robcall_ext = 1 if id == 46011 replace robcall_ext = 1 if id == 46014 replace robcall_ext = 1 if id == 46013 replace robocall = 0 if year == 2006 replace robcall_ext = 0 if year == 2006 egen pollid = group(id pollnum pollplace) gsort pollid year split(pollnum), parse("A" "B" "-" "C" "D" "E" "F" "G" "H" "I" "J" "K") replace pollnum1 = "-"+pollnum2 if pollnum1 == "" replace pollnum1 = "-1" if pollnum1 == "NaN" split(pollnum1), parse("A" .... "K" "L" "M" "N") destring(pollnum11), replace drop pollnum2 gen turnout = 100*totalvotes/voters gen convoteshare = 100*conservative/totalvotes gen oppvoteshare = 100*(bloc+greenparty+liberal+ndp)/totalvotes gen contendervoteshare = 100*(contendervotes)/totalvotes /* Generate sample */ gen absentee = 0 replace absentee = 1 if (pollplace == "Group 1/Groupe 1" | pollplace == "Group 2/Groupe 2") gen advance = 0 replace advance = 1 if pollnum11 > 599 & pollnum11 < 700 gen mobile = 0 replace mobile = 1 if pollnum11 > 499 & pollnum11 < 600 gen insample = 1 replace insample = 0 if (absentee==1|mobile==1) * this gets rid of Andre Arthur's riding. Conservatives did not run in 2008 drop if id==24051 * this gets rid of Saanich Gulf Islands. Ro drop if id==59024 save "master2008", replace drop if year == 2008 replace year = 2008 foreach v of varlist * { rename `v' lag`v' } rename lagid id rename lagname name rename lagpollnum pollnum rename lagpollplace pollplace rename lagyear year rename lagpollid pollid rename lagname1 name1 rename laginsample insample drop id sort name pollnum pollplace year save "lags2008", replace use "master2008", replace sort name pollnum pollplace year merge name pollnum pollplace year using "lags2008" drop if _merge == 2 rename _merge islag drop if id==0 by id, sort: egen n_polls2008=count(lagoppvoteshare) if (year==2008&insample==1) /**** Generate Interactions *****/ gen interact = lagoppvoteshare*robocall gen interact_ext=lagoppvoteshare*robcall_ext gen interact_con=lagcontendervoteshare*robocall /*** Generate weights ***/ sum edvotes if pollplace == "Group 1/Groupe 1" & year == 2008 gen weights = round(1/edvotes*`r(mean)') gen turnoutdiff2008=turnout-lagturnout gen oppvotesharediff2008=oppvoteshare-lagoppvoteshare gen edmargin2008=edmargin /****SUMMARY STATS*****/ tabstat lagcons robocall robcall_ext edmargin edvotes edvoters n_polls turnout lagoppvoteshare if year==2008, statistics(mean sd median min max count) *tabstat lagcons robocall robcall_ext edmargin edvotes edvoters n_polls turnout lagoppvoteshare if year==2006, statistics(mean sd median min max count) by robocall, sort: su edvotes edvoters turnout edmargin turnout sort id pollid year save final_data_noc2006.dta, replace /***********generating district level data for 2008 ******************/ by id, sort: egen edoppvotes2008 = sum(liberal+greenparty+ndp+bloc) by id, sort: egen edcontendervotes2008 = total(contendervotes) by id, sort: egen edoppvotes2006 = sum(lagliberal+laggreenparty+lagndp+lagbloc) by id, sort: egen edcontendervotes2006 = total(lagcontendervotes) gen edoppvoteshare2008=100*edoppvotes2008/edvotes gen winmargin2008 = 100*edmargin/edvotes gen edturnout2008=100*edvotes/edvoters gen edoppvoteshare2006=100*edoppvotes2006/lagedvotes gen winmargin2006 = 100*lagedmargin/lagedvotes gen edturnout2006=100*lagedvotes/lagedvoters gen turnoutdiff0806=(edturnout2008-edturnout2006)*100 gen oppvotesharediff0806=edoppvoteshare2008-edoppvoteshare2006 drop year gen year=2011 sort id pollnum year save final_test_spending_data.dta, replace /******generating the panel data for the time trend estimations ************/ use final_data_noc2006.dta, clear drop year gen year=2011 keep year robocall pollnum1 lagturnout lagoppvoteshare name lagvoters lagtotalvotes lagedmargin edmargin2008 oppvotesharediff2008 turnoutdiff2008 pollplace pollid pollnum1 sort name merge name using id.dta rename turnoutdiff2008 turnoutdiff0806 rename lagturnout turnout2006 rename lagoppvoteshare oppvoteshare2006 rename lagvoters voters2006 rename lagtotalvotes totalvotes2006 rename lagedmargin edmargin2006 rename oppvotesharediff oppvotesharediff0806 gen interact2006=oppvoteshare2006*robocall drop _merge sort id pollnum1 year save final_data_noc2006test.dta, replace use final_data_noc.dta, clear sort id pollnum1 year merge id pollnum1 year using final_data_noc2006test.dta keep if _merge==3 rename lagturnout turnout2008 rename lagoppvoteshare oppvoteshare2008 rename lagvoters voters2008 rename lagtotalvotes totalvotes2008 gen turnoutdiff1108=turnout-turnout2008 gen oppvotesharediff1108=oppvoteshare-oppvoteshare2008 gen interact2008=oppvoteshare2008*robocall areg turnoutdiff1108 turnoutdiff0806 oppvoteshare2008, absorb(id) areg turnoutdiff1108 turnoutdiff0806 oppvoteshare2008 interact, absorb(id) probit robocall turnoutdiff0806 oppvoteshare2008 gen interact_oppv = oppvoteshare2008*turnoutdiff0806 areg turnoutdiff1108 turnoutdiff0806 oppvoteshare2008 interact_oppv interact, absorb(id) probit robocall turnoutdiff0806 oppvoteshare2008 interact_oppv probit robocall turnout2008 turnoutdiff0806 oppvoteshare2008 interact_oppv mfx areg turnout turnout2008 oppvoteshare2008 turnoutdiff0806 interact, absorb(id) cl(id) ro gen interact_diff = robocall*turnoutdiff0806 areg turnout turnout2008 oppvoteshare2008 turnoutdiff0806 interact_diff interact, absorb(id) cl(id) ro save final_data_test2006.dta