*********************************************
*AnalyzeWAVotersVBM.do
**
*Analyze the treatment effect of Washington counties who
*switched to all-mail elections on individual registrants,
*identifying heterogeneous treatment effects by individual
*characteristic.
**
*Note: this code is memory intensive, and requires a Stata version
*that can handle large matrices and memory.
**
*Alan Gerber, Gregory Huber, Seth Hill, "Identifying the Effects of Elections Held All-Mail on
*Turnout: Staggered Reform in the Evergreen State."
*********************************************

set more off
qui set mem 12g
qui set matsize 11000
capture set maxvar 7500
capture log close

clear
*Debug by sampling; set to 1 to take a 10 percent sample of data to improve
*speed of analysis.
local debug 0

do 03_SUB_RecodeStackedDataArchive.do `debug'

* Before saving public replication archive, rejigger id's and precinct codes so data can't be used to recreate public vote file.

* new randomly assigned id
sort statevoterid
set seed 12312312
gen x=uniform()
sort x
replace statevoterid=string(_n)
drop x
* new made up precinct #
egen temp=group(precinctcode)
replace precinctcode = string(temp)
drop temp
* new made up precinct/year fe
egen temp=group(countyprec)
replace countyprec = string(temp)
drop temp

drop *birth* *leg* *cong* hh_group num_in_hh *regis* 

compress

save PublicReplicationDataset.dta, replace

rm PriorTurnoutByPrecinct.dta
rm WA_Voter_All_Histories_200812.dta
rm WA_Voter_All_Histories_201012.dta
rm WA_Voter_All_Registrants_200701.dta
rm WA_Voter_All_Registrants_200812.dta
rm WA_Voter_All_Registrants_201012.dta
rm WA_Voter_UniqueAddresses_200812.csv
rm WaVoterForAnalysis0608.dta
rm WaVoterForAnalysis0810.dta

