/************************ Robocall Study merge.do file created: March 10, 2012 file updated: March 12, 2012 This program takes the raw-data and merges them into the final dataset (without campaign spending) *************************/ /********************** * 1. Inputs and settings **********************/ clear *clear matrix 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/robocalls/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 merge.txt, text replace; /**** upload mater data ****/ tempfile lags201l tempfile master2011 use 2008\master_data2011.dta, replace append using 2008\master_data2008.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 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 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 == 2008 replace robcall_ext = 0 if year == 2008 /**** Collapse non-matching polling stations into larger units so as many match as possible (optional) ****/ /**** COMMENT OUT **** local collapse = 1 if `collapse' == 1 { save "master2011", replace drop if year == 2011 replace year = 2011 keep id year name pollplace pollnum save "polls2008to11match", replace use "master2011", replace merge 1:1 id year name pollnum pollplace using "polls2008to11match" drop if _merge == 2 rename _merge islag egen pollid0 = group(id pollnum pollplace) 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" gen newpollnum = pollnum1 destring(pollnum1), replace drop pollnum2 gsort pollid0 bysort pollid0: egen matched = count(id) replace matched = matched - 1 gsort id pollnum1 year bysort id pollnum1 : egen allmatched = mean(matched) replace allmatched = 0 if allmatched < 1 replace newpollnum = pollnum if allmatched == 1 egen pollid = group(id newpollnum pollplace) gsort pollid destring pollnum1, replace collapse (sum) conservative-bloc invalid-voters contendervotes (mean) edonevotes-edmargin edvoters-edvotes /* */, by(id year newpollnum pollid contendername prov name pollplace pollnum1 name1 robocall robcall_ext) rename newpollnum pollnum local filehand = "final_data_col_new.dta" } else { **** COMMENT OUT ****/ /**** Generate variables of interest ****/ 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" destring(pollnum1), 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 gen edturnout=100*edvotes/edvoters by id, sort: egen edoppvotes = sum(liberal+greenparty+ndp+bloc) gen edoppvoteshare=100*edoppvotes/edvoters /* } paired with to COMMENT OUT above */ /**** Set sample ****/ * 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. Robocalling reported in 2008 drop if id==59024 /**** this gets rid of absentee, advance, and mobile polls, where the expected effect of robocalls is zero ****/ gen insample = 1 replace insample = 0 if (pollplace == "Group 1/Groupe 1" | pollplace == "Group 2/Groupe 2" | pollplace == "Mobile poll/Bureau itinérant") by id, sort: egen n_polls2011=count(edmargin) if (year==2011&insample==1) save "master2011", replace drop if year == 2011 replace year = 2011 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 sort id pollnum pollplace year save "lags2011", replace use "master2011", replace sort id pollnum pollplace year merge id pollnum pollplace year using "lags2011" drop if _merge == 2 rename _merge islag * Generate interaction terms gen interact = lagoppvoteshare*robocall gen interact_ext=lagoppvoteshare*robcall_ext gen interact_con=lagcontendervoteshare*robocall * Generate poll characteristics gen absentee = 0 replace absentee = 1 if (pollplace == "Group 1/Groupe 1" | pollplace == "Group 2/Groupe 2") gen advance = 0 replace advance = 1 if pollnum1 > 599 & pollnum1 < 700 gen mobile = 0 replace mobile = 1 if pollnum1 > 499 & pollnum1 < 600 * Generate Weights sum edvotes if pollplace == "Group 1/Groupe 1" & year == 2011 gen weights = round(1/edvotes*`r(mean)') gen weights_alt = round(totalvotes/edvotes*`r(mean)') /****SUMMARY STATS*****/ tabstat lagcons robocall robcall_ext edmargin edvotes edvoters n_polls turnout lagedoppvoteshare if year==2011, statistics(mean sd median min max count) tabstat lagcons robocall robcall_ext edmargin edvotes edvoters n_polls edturnout lagedoppvoteshare if year==2008, statistics(mean sd median min max count) by robocall, sort: su edvotes edvoters edturnout edmargin lagedoppvoteshare sort id pollid year save final_data_noc.dta, replace keep id name edturnout lagedturnout lagedoppvoteshare robocall lagedmargin prov year drop if year==2008 duplicates drop id, force save cross_section.dta, replace