diff --git a/29/paper.pdf b/29/paper.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4df518cc07b8fabfb583f5af255ec201db0e34de --- /dev/null +++ b/29/paper.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15d29b2b15d48f28c8e6962fa1ba757e5175e6d2cf7ff1a146329c8c95a7aa2f +size 2599693 diff --git a/29/replication_package/Code/.Rhistory b/29/replication_package/Code/.Rhistory new file mode 100644 index 0000000000000000000000000000000000000000..973df2968228877c9ebb4bf83297be97e829716e --- /dev/null +++ b/29/replication_package/Code/.Rhistory @@ -0,0 +1,512 @@ +} +# Determine intervals between values of the moderator +if (incr == "default"){ +increment = (max_val - min_val)/(num_points - 1) +}else{ +increment = incr +} +# Create list of moderator values at which marginal effect is evaluated +x_2 <- seq(from=min_val, to=max_val, by=increment) +# Compute marginal effects +delta_1 = beta_1 + beta_3*x_2 +# Compute variances +var_1 = covMat[effect,effect] + (x_2^2)*covMat[interaction, interaction] + 2*x_2*covMat[effect, interaction] +# Standard errors +se_1 = sqrt(var_1) +# Upper and lower confidence bounds +z_score = qnorm(1 - ((1 - conf)/2)) +upper_bound = sapply(1:length(z_score), function(x) delta_1 + z_score[x]*se_1) +lower_bound = sapply(1:length(z_score), function(x) delta_1 - z_score[x]*se_1) +# Determine the bounds of the graphing area +max_y = max(upper_bound) +min_y = min(lower_bound) +# Make the histogram color +hist_col = colr +stars <- ifelse(abs(summary(model)$coefficients[interaction,3]) >2.6,"***", +ifelse(abs(summary(model)$coefficients[interaction,3]) > 1.96,"**", +ifelse(abs(summary(model)$coefficients[interaction,3]) > 1.65,"*",""))) +est <- paste("Interaction: ",round(summary(model)$coefficients[interaction,1],3),stars," (", +round(summary(model)$coefficients[interaction,2],3),")",sep="") +# Initialize plotting window +if(plot) { +plot(x=c(), y=c(), ylim=c(min_y, max_y), xlim=c(min_val, max_val), +xlab=xlabel, ylab=ylabel, main=title) +# Plot estimated effects +if(!pointsplot) { +lines(y=delta_1, x=x_2,col = colr) +for(i in ncol(upper_bound):1) { +polygon(c(x_2,rev(x_2)),c(upper_bound[,i],rev(lower_bound[,i])),border = NA, +col = colr) +} +}else{ +points(y = delta_1,x = x_2,col = colr,pch = 19) +for(i in ncol(upper_bound):1) { +segments(x_2,upper_bound[,i],x_2,lower_bound[,i],col = colr,lwd = i) +} +} +# Add a dashed horizontal line for zero +abline(h=0, lty=3) +# Add a vertical line at the mean +if (mean){ +abline(v = mean(mod_frame[[moderator]]), lty=2, col="red") +} +# Add a vertical line at the median +if (median){ +abline(v = median(mod_frame[[moderator]]), lty=3, col="blue") +} +# Add Rug plot +if (rugplot){ +rug(mod_frame[[moderator]]) +} +if (show_est) { +text(par('usr')[ 2 ], par('usr')[ 4 ],adj=c(1.05,1.2), +labels = est) +} +#Add Histogram (Histogram only plots when minimum and maximum are the min/max of the moderator) +if (histogram & minimum=="min" & maximum=="max"){ +par(new=T) +hist(mod_frame[[moderator]], axes=F, xlab="", ylab="",main="", border=hist_col, col=hist_col) +} +} +return(list(delta_1 = delta_1,x_2 = x_2,ub = upper_bound,lb = lower_bound,inc = increment,est = est)) +} +####################################################################################################################### Preparing variables +Y <- paste0(c("pct_","VAP_","pcttw_"),"sanders") +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp",'caucus_switch','caucus', +"sc_CTY_LT30yo","sc_CTY_60Up",#"sc_CTY_Old_age_dep_ratio", +"sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", +"sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", +"sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", +"sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", +"ln_CTY_tot_pop","sc_turnout_pct_20") +####################################################################################################################### Looping across specifications +finalDat$sc_turnout_pct_chg <- scale(finalDat$turnout_pct_chg) +finalDat$sc_VAP_turnout_20 <- scale(finalDat$VAP_turnout_20) +####################################################################################################################### Looping across specifications +resRegs <- resBal <- resTabs <- list() +y +Y <- c('pct_sanders16') +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","stab") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp",'caucus_switch','caucus', +"sc_CTY_LT30yo","sc_CTY_60Up",#"sc_CTY_Old_age_dep_ratio", +"sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", +"sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", +"sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", +"sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English", +"sc_CTY_White","sc_CTY_Black_or_African_American", +"ln_CTY_tot_pop","sc_turnout_pct_20") +####################################################################################################################### Looping across specifications +resRegs <- resBal <- resTabs <- list() +for(y in Y) { +for(d in D[c(1:3)]) { +for(fe in FE) { +stars <- list() +for(dateThresh in c("2020-01-01","2020-03-01")) { +if(dateThresh == '2020-03-01') { +covs <- covariates[-which(covariates == 'caucus')] +} else { +covs <- covariates +} +if(!is.null(resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$felm$cont)) { next } +finalDat$treatBin <- ifelse(finalDat[[gsub("sc_|ln_","",d)]] > 1,1,0) +foranal.weight <- finalDat %>% select(y,d,treatBin,gsub("sc_|ln_","",d),DMA_CODE,date,stab,covs) %>% +filter(complete.cases(.),date >= as.Date(dateThresh)) +m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(covs,collapse = " + "))), +data = foranal.weight, +method = "nearest", +distance = "mahalanobis") +m.data <- match.data(m.out) +W.out <- weightit(formula(paste0("treatBin ~ ",paste(covs,collapse = " + "))), +data = foranal.weight, estimand = "ATT", method = "cbps") +# Balance tables +balt.pre <- bal.tab(formula(paste0("treatBin ~ ",paste(covs,collapse = " + "))), +data = foranal.weight, estimand = "ATT",m.threshold = .05) +balt.post <- bal.tab(W.out, m.threshold = .05, disp.v.ratio = TRUE) +unm <- data.frame(Covs = rownames(balt.pre$Balance), +balt.pre$Balance %>% mutate(Diff_Unm = round(Diff.Un,2), +Bal_Test_Unm = M.Threshold.Un)) %>% +select(Covs,Diff_Unm,Bal_Test_Unm) +match <- data.frame(Covs = rownames(balt.post$Balance), +balt.post$Balance %>% mutate(Diff_Match = round(Diff.Adj,2), +Bal_Test_Match = M.Threshold)) %>% +select(Covs,Diff_Match,Bal_Test_Match) +# balTab <- match %>% left_join(unm) %>% select(Covs,Diff_Unm,Bal_Test_Unm,Diff_Match,Bal_Test_Match) +# balTab$Covs <- Hmisc::capitalize(trimws(gsub("manufactur","Manufacturing",gsub("labor force part rate","LFPR", +# gsub("hher|hhs","HH",gsub("bachelor s","Bachelor's",gsub("_"," ",gsub("sc_|cty_|age_18_64|pop_16_over|hh$|poppct","",tolower(balTab$Covs))))))))) +# resBal[[y]][[d]][[fe]][[dateThresh]]$balTab <- balTab +# resBal[[y]][[d]][[fe]][[dateThresh]]$balPlot <- qqprep(m.out) +# Basic +resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$felm$cont <- summary(stars$cont[[paste0(dateThresh,"_1")]] <- felm(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),finalDat %>% filter(date >= as.Date(dateThresh))))$coefficients +resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$felm$bin <- summary(stars$bin[[paste0(dateThresh,"_1")]] <- felm(as.formula(paste0("scale(",y,") ~ treatBin + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),finalDat %>% filter(date >= as.Date(dateThresh))))$coefficients +# Matching +resRegs[[y]][[d]][[fe]][[dateThresh]]$matching$felm$cont <- summary(stars$cont[[paste0(dateThresh,"_2")]] <- felm(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resRegs[[y]][[d]][[fe]][[dateThresh]]$matching$felm$bin <- summary(stars$bin[[paste0(dateThresh,"_2")]] <- felm(as.formula(paste0("scale(",y,") ~ treatBin + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +# Weighting +resRegs[[y]][[d]][[fe]][[dateThresh]]$weighting$felm$cont <- summary(stars$cont[[paste0(dateThresh,"_3")]] <- felm(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),foranal.weight,weights = W.out$weights))$coefficients +resRegs[[y]][[d]][[fe]][[dateThresh]]$weighting$felm$bin <- summary(stars$bin[[paste0(dateThresh,"_3")]] <- felm(as.formula(paste0("scale(",y,") ~ treatBin + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),foranal.weight,weights = W.out$weights))$coefficients +if(fe != "0") { +resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$lmer <- summary(lmer(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," + (1| ",fe,")")),finalDat %>% filter(date >= as.Date(dateThresh))))$coefficients +resRegs[[y]][[d]][[fe]][[dateThresh]]$matching$lmer <- summary(lmer(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," + (1| ",fe,")")),m.data,weights = m.data$weights))$coefficients +resRegs[[y]][[d]][[fe]][[dateThresh]]$weighting$lmer <- summary(lmer(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," + (1| ",fe,")")),foranal.weight,weights = W.out$weights))$coefficients +} +# covars <- rownames(stars$cont[[1]]$coefficients) +# labs <- gsub("Lths","LTHS",gsub("Collup","Coll. Up",gsub("Md inc HH","Med HH Inc",gsub("Sc ","",gsub(" or african american|band$","",Hmisc::capitalize(trimws(gsub("manufactur","manufacturing",gsub("hher|hhs","HH",gsub("labor force part rate","LFPR",gsub("bachelor s","bachelor's",gsub("age 18 64|pop 16 over|hh$|poppct","",gsub("\\_"," ",gsub("^sc_|^.*cty\\_","",tolower(covars))))))))))))))) +# resTabs[[y]][[d]][[fe]]$cont$html <- stargazer(stars$cont,type = "html",keep.stat = c("n","rsq"),covariate.labels = labs) +# resTabs[[y]][[d]][[fe]]$cont$tex <- stargazer(stars$cont,keep.stat = c("n","rsq"),covariate.labels = labs) +# covars <- rownames(stars$bin[[1]]$coefficients) +# labs <- gsub("Lths","LTHS",gsub("Collup","Coll. Up",gsub("Md inc HH","Med HH Inc",gsub("Sc ","",gsub(" or african american|band$","",Hmisc::capitalize(trimws(gsub("manufactur","manufacturing",gsub("hher|hhs","HH",gsub("labor force part rate","LFPR",gsub("bachelor s","bachelor's",gsub("age 18 64|pop 16 over|hh$|poppct","",gsub("\\_"," ",gsub("^sc_|^.*cty\\_","",tolower(covars))))))))))))))) +# resTabs[[y]][[d]][[fe]]$bin$html <- stargazer(stars$bin,type = "html",keep.stat = c("n","rsq"),covariate.labels = labs) +# resTabs[[y]][[d]][[fe]]$bin$tex <- stargazer(stars$bin,keep.stat = c("n","rsq"),covariate.labels = labs) +} +} +cat(y,"\n") +} +} +toplot <- NULL +for(fe in names(resRegs$pct_sanders16$sc_DMA_cases)) { +for(mod in c('basic','matching','weighting')) { +for(meas in c('bin','cont')) { +tmp <- resRegs$pct_sanders16$sc_DMA_cases[[fe]]$`2020-01-01`[[mod]]$felm[[meas]][2,] +if(is.null(tmp)) { next } +tmp <- data.frame(t(tmp)) +colnames(tmp) <- c('est','se','tstat','pval') +tmp$fe <- fe +tmp$mod <- mod +tmp$meas <- meas +toplot <- bind_rows(toplot,tmp) +} +} +} +toplot %>% +filter(meas != 'cont') %>% +mutate(fe = factor(ifelse(fe == 0,'None', +ifelse(fe == 'DMA_CODE','DMA','State')),levels = c('None','DMA','State'))) %>% +ggplot(aes(x = fe,y = est,color = mod)) + +geom_point(position = position_dodge(width = .2)) + +geom_errorbar(aes(ymin = est - 2*se,ymax = est+2*se),width = .1, +position = position_dodge(width = .2)) + +geom_hline(yintercept = 0,linetype = 'dashed') + +scale_color_manual(name = 'Model',values = c('basic' = 'grey70', +'matching' = 'grey40', +'weighting' = 'black')) + +xlab('Fixed Effect') + ylab('Effect of Covid Exposure on Bernie 2016') + +theme_ridges() +list.files('./') +# Master script +for(f in list.files('./')) { +if(grepl('helper_functions|MASTER|LOG',f)) { next } +# stop() +con <- file(paste0('./LOG/log_',gsub('.R','.txt',f))) +cat(f,'\n') +sink(con,append = TRUE) +sink(con,append = TRUE,type = 'message') +source(f,echo = T,max.deparse.length = 10000) +sink() +sink(type = 'message') +} +list.files('./') +file.exits(paste0('./LOG/log_',gsub('.R','.txt',f))) +file.exists(paste0('./LOG/log_',gsub('.R','.txt',f))) +# Master script +for(f in list.files('./')) { +if(grepl('helper_functions|MASTER|LOG',f)) { next } +if(file.exists(paste0('./LOG/log_',gsub('.R','.txt',f)))) { next } +# stop() +con <- file(paste0('./LOG/log_',gsub('.R','.txt',f))) +cat(f,'\n') +sink(con,append = TRUE) +sink(con,append = TRUE,type = 'message') +source(f,echo = T,max.deparse.length = 10000) +sink() +sink(type = 'message') +} +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(gridExtra) +require(ggridges) +require(ggrepel) +require(CBPS) +require(tidyverse) +rm(list = ls()) +gc() +####################################################################################################################### Loading data +load('../Data/replication_data.RData') +####################################################################################################################### Loading functions +source('./helper_functions.R') +# ####################################################################################################################### Command line arguments +# args <- commandArgs(trailingOnly = T) +# # args <- c(3,2,2,2) +# # Y: 1-3 +# # D: 1-2 +# # FE: 1-4 +# # GEO: 1-2 +# yInd <- as.numeric(args[1]) +# dInd <- as.numeric(args[2]) +# feInd <- as.numeric(args[3]) +# geoInd <- as.numeric(args[4]) +####################################################################################################################### Preparing variables +Y <- paste0(c("pct_","VAP_","pcttw_"),"sanders") +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp", +"sc_CTY_LT30yo","sc_CTY_60Up", +"sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", +"sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", +"sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", +"sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", +"ln_CTY_tot_pop","sc_turnout_pct_20") +set.seed(123) +resSI <- list() +for(y in 'pcttw_sanders') { +for(fe in c('DMA_CODE','0')) { +for(geo in 'DMA_') { +for(d in c('March10Cases','March17Cases')) { +for(pre in c("2020-03-01","2020-03-03","2020-03-10","2020-03-17")) { +for(post in c("2020-03-01","2020-03-03","2020-03-10","2020-03-17")) { +if(pre == post) { next } +if(pre == "2020-03-01") { +finalDat$post <- ifelse(finalDat$date == as.Date(post),1, +ifelse(finalDat$date <= as.Date(pre),0,NA)) +} else if(post == "2020-03-01") { +finalDat$post <- ifelse(finalDat$date <= as.Date(post),1, +ifelse(finalDat$date == as.Date(pre),0,NA)) +} else { +finalDat$post <- ifelse(finalDat$date == as.Date(post),1, +ifelse(finalDat$date == as.Date(pre),0,NA)) +} +finalDat$treatBin <- ifelse(finalDat[[paste0(geo,d)]] > 1,1,0) +finalDat$treat <- ifelse(finalDat$post == 1 & finalDat$treatBin == 1,1,0) +tmpAnal <- finalDat %>% select(Y,treat,treatBin,c(covariates,paste0(y,"16")),pcttw_sanders16,VAP_sanders16,DMA_CODE,date,stab,matches("cases"),post) %>% filter(complete.cases(.)) +m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, +method = "nearest", +distance = "mahalanobis") +m.data <- match.data(m.out) +W.out <- weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, estimand = "ATT", method = "cbps") +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) +# Permutation SHEEYAHT +basic.bin.plac <- basic.cont.plac <- basic.did.plac <- matching.bin.plac <- matching.cont.plac <- matching.did.plac <- weighting.bin.plac <- weighting.cont.plac <- weighting.did.plac <- NULL +for(bs in 1:100) { +tmpAnal$perm <- sample(tmpAnal[[paste0(geo,d)]],size = nrow(tmpAnal)) +tmpAnal$treatBin <- ifelse(tmpAnal$perm > 1,1,0) +tmpAnal$treat <- ifelse(tmpAnal$post == 1 & tmpAnal$treatBin == 1,1,0) +m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, +method = "full", +distance = "mahalanobis") +m.data <- match.data(m.out) +W.out <- weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, estimand = "ATT", method = "cbps") +test <- tryCatch(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights),error = function(e) e) +if(inherits(test,"error")) { next } +basic.bin.plac <- c(basic.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients['treat',1]) +basic.cont.plac <- c(basic.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients["scale(perm)",1]) +basic.did.plac <- c(basic.did.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients["treatBin:post",1]) +matching.bin.plac <- c(matching.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients['treat',1]) +matching.cont.plac <- c(matching.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients["scale(perm)",1]) +matching.did.plac <- c(matching.did.plac, +summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients["treatBin:post",1]) +weighting.bin.plac <- c(weighting.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients['treat',1]) +weighting.cont.plac <- c(weighting.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients["scale(perm)",1]) +weighting.did.plac <- c(weighting.did.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients["treatBin:post",1]) +cat(".") +} +cat('\n') +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$bin <- basic.bin.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$cont <- basic.cont.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$did <- basic.did.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$bin <- matching.bin.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$cont <- matching.cont.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$did <- matching.did.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$bin <- weighting.bin.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$cont <- weighting.cont.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$did <- weighting.did.plac +} +} +} +} +} +cat(y," done\n") +} +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(gridExtra) +require(ggridges) +require(ggrepel) +require(CBPS) +require(tidyverse) +rm(list = ls()) +gc() +####################################################################################################################### Loading data +load('../Data/replication_data.RData') +####################################################################################################################### Loading functions +source('./helper_functions.R') +# ####################################################################################################################### Command line arguments +# args <- commandArgs(trailingOnly = T) +# # args <- c(3,2,2,2) +# # Y: 1-3 +# # D: 1-2 +# # FE: 1-4 +# # GEO: 1-2 +# yInd <- as.numeric(args[1]) +# dInd <- as.numeric(args[2]) +# feInd <- as.numeric(args[3]) +# geoInd <- as.numeric(args[4]) +####################################################################################################################### Preparing variables +Y <- paste0(c("pct_","VAP_","pcttw_"),"sanders") +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp", +"sc_CTY_LT30yo","sc_CTY_60Up", +"sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", +"sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", +"sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", +"sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", +"ln_CTY_tot_pop","sc_turnout_pct_20") +set.seed(123) +resSI <- list() +for(y in 'pcttw_sanders') { +for(fe in c('DMA_CODE','0')) { +for(geo in 'DMA_') { +for(d in c('March10Cases','March17Cases')) { +for(pre in c("2020-03-01","2020-03-03","2020-03-10","2020-03-17")) { +for(post in c("2020-03-01","2020-03-03","2020-03-10","2020-03-17")) { +if(pre == post) { next } +if(pre == "2020-03-01") { +finalDat$post <- ifelse(finalDat$date == as.Date(post),1, +ifelse(finalDat$date <= as.Date(pre),0,NA)) +} else if(post == "2020-03-01") { +finalDat$post <- ifelse(finalDat$date <= as.Date(post),1, +ifelse(finalDat$date == as.Date(pre),0,NA)) +} else { +finalDat$post <- ifelse(finalDat$date == as.Date(post),1, +ifelse(finalDat$date == as.Date(pre),0,NA)) +} +finalDat$treatBin <- ifelse(finalDat[[paste0(geo,d)]] > 1,1,0) +finalDat$treat <- ifelse(finalDat$post == 1 & finalDat$treatBin == 1,1,0) +tmpAnal <- finalDat %>% select(Y,treat,treatBin,c(covariates,paste0(y,"16")),pcttw_sanders16,VAP_sanders16,DMA_CODE,date,stab,matches("cases"),post) %>% filter(complete.cases(.)) +m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, +method = "nearest", +distance = "mahalanobis") +m.data <- match.data(m.out) +W.out <- weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, estimand = "ATT", method = "cbps") +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) +# Permutation SHEEYAHT +basic.bin.plac <- basic.cont.plac <- basic.did.plac <- matching.bin.plac <- matching.cont.plac <- matching.did.plac <- weighting.bin.plac <- weighting.cont.plac <- weighting.did.plac <- NULL +for(bs in 1:100) { +tmpAnal$perm <- sample(tmpAnal[[paste0(geo,d)]],size = nrow(tmpAnal)) +tmpAnal$treatBin <- ifelse(tmpAnal$perm > 1,1,0) +tmpAnal$treat <- ifelse(tmpAnal$post == 1 & tmpAnal$treatBin == 1,1,0) +m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, +method = "full", +distance = "mahalanobis") +m.data <- match.data(m.out) +W.out <- weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), +data = tmpAnal, estimand = "ATT", method = "cbps") +test <- tryCatch(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights),error = function(e) e) +if(inherits(test,"error")) { next } +basic.bin.plac <- c(basic.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients['treat',1]) +basic.cont.plac <- c(basic.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients["scale(perm)",1]) +basic.did.plac <- c(basic.did.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients["treatBin:post",1]) +matching.bin.plac <- c(matching.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients['treat',1]) +matching.cont.plac <- c(matching.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients["scale(perm)",1]) +matching.did.plac <- c(matching.did.plac, +summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients["treatBin:post",1]) +weighting.bin.plac <- c(weighting.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients['treat',1]) +weighting.cont.plac <- c(weighting.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients["scale(perm)",1]) +weighting.did.plac <- c(weighting.did.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients["treatBin:post",1]) +cat(".") +} +cat('\n') +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$bin <- basic.bin.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$cont <- basic.cont.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$did <- basic.did.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$bin <- matching.bin.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$cont <- matching.cont.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$did <- matching.did.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$bin <- weighting.bin.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$cont <- weighting.cont.plac +resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$did <- weighting.did.plac +} +} +} +} +} +cat(y," done\n") +} +# Master script +for(f in list.files('./')) { +if(grepl('helper_functions|MASTER|LOG',f)) { next } +if(file.exists(paste0('./LOG/log_',gsub('.R','.txt',f)))) { next } +stop() +con <- file(paste0('./LOG/log_',gsub('.R','.txt',f))) +cat(f,'\n') +sink(con,append = TRUE) +sink(con,append = TRUE,type = 'message') +source(f,echo = T,max.deparse.length = 10000) +sink() +sink(type = 'message') +} +f +# stop() +con <- file(paste0('./LOG/log_',gsub('.R','.txt',f))) +cat(f,'\n') +sink(con,append = TRUE) +sink(con,append = TRUE,type = 'message') +source(f,echo = T,max.deparse.length = 10000) +sink() +sink(type = 'message') +# Master script +for(f in list.files('./')) { +if(grepl('helper_functions|MASTER|LOG',f)) { next } +if(file.exists(paste0('./LOG/log_',gsub('.R','.txt',f)))) { next } +# stop() +con <- file(paste0('./LOG/log_',gsub('.R','.txt',f))) +cat(f,'\n') +sink(con,append = TRUE) +sink(con,append = TRUE,type = 'message') +source(f,echo = T,max.deparse.length = 10000) +sink() +sink(type = 'message') +} diff --git a/29/replication_package/Code/Figure 2, 3, Table SI1.R b/29/replication_package/Code/Figure 2, 3, Table SI1.R new file mode 100644 index 0000000000000000000000000000000000000000..7364a71a63e3ebfc9aa266b31fddb552bc2469c0 --- /dev/null +++ b/29/replication_package/Code/Figure 2, 3, Table SI1.R @@ -0,0 +1,183 @@ +# File name: figure2_figure3_SItable1.R +# In: +# - replication_data.RData +# Out: +# - /Figures/figure2.pdf +# - /Figures/figure3.pdf +# - /Tables/SI-table1.tex + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(sf) +require(leaflet) +require(ggridges) +require(ggthemes) +require(gridExtra) + +rm(list = ls()) +gc() +########################################################################################## Loading data +load('../Data/replication_data.RData') + + +# Figure 2: Map (compressed to PNG in manuscript) +toplot <- maps$county %>% filter(!state %in% c("Alaska","Hawaii")) +toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Throckmorton','Knox'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Baylor'))]) +toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Montague'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Wise'))]) +toplot$DMA.CODE[which(toplot$state == 'Colorado' & toplot$name %in% c('Cheyenne'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Colorado' & toplot$name %in% c('Kiowa'))]) +toplot$DMA.CODE[which(toplot$state == 'Nebraska' & toplot$name %in% c('Hooker','Arthur','Blaine'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Nebraska' & toplot$name %in% c('Thomas'))]) +toplot$DMA.CODE[which(toplot$state == 'Wyoming' & toplot$name %in% c('Johnson'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Wyoming' & toplot$name %in% c('Natrona'))]) +toplot$DMA.CODE[which(toplot$state == 'Iowa' & toplot$name %in% c('Emmet'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Minnesota' & toplot$name %in% c('Martin'))]) +toplot$DMA.CODE[which(toplot$state == 'Minnesota' & toplot$name %in% c('Nicollet'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Minnesota' & toplot$name %in% c('Sibley'))]) +toplot$DMA.CODE[which(toplot$state == 'Illinois' & toplot$name %in% c('Edgar'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Illinois' & toplot$name %in% c('Clark'))]) +toplot$DMA.CODE[which(toplot$state == 'Kentucky' & toplot$name %in% c('Adair','Cumberland'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Kentucky' & toplot$name %in% c('Metcalfe'))]) +toplot$DMA.CODE[which(toplot$state == 'Ohio' & toplot$name %in% c('Athens'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Ohio' & toplot$name %in% c('Meigs'))]) +toplot$DMA.CODE[which(toplot$state == 'Ohio' & toplot$name %in% c('Guernsey','Noble'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Ohio' & toplot$name %in% c('Belmont'))]) +toplot$DMA.CODE[which(toplot$state == 'Arkansas' & toplot$name %in% c('Nevada'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Arkansas' & toplot$name %in% c('Columbia'))]) +toplot$DMA.CODE[which(toplot$state == 'Tennessee' & toplot$name %in% c('Gibson','Chester'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Tennessee' & toplot$name %in% c('McNairy'))]) +toplot$DMA.CODE[which(toplot$state == 'South Carolina' & toplot$name %in% c('Saluda'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'South Carolina' & toplot$name %in% c('Edgefield'))]) +toplot$DMA.CODE[which(toplot$state == 'California' & toplot$name %in% c('Modoc'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'California' & toplot$name %in% c('Siskiyou'))]) +toplot$DMA.CODE[which(toplot$state == 'Arkansas' & toplot$name %in% c('Johnson'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Arkansas' & toplot$name %in% c('Pope'))]) +toplot$DMA.CODE[which(toplot$state == 'Colorado' & toplot$name %in% c('Custer'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Colorado' & toplot$name %in% c('Saguache'))]) +toplot$DMA.CODE[which(toplot$state == 'Wyoming' & toplot$name %in% c('Lincoln'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Wyoming' & toplot$name %in% c('Teton'))]) +toplot$DMA.CODE[which(toplot$state == 'Nebraska' & toplot$name %in% c('Banner'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Nebraska' & toplot$name %in% c('Morrill'))]) +toplot$DMA.CODE[which(toplot$state == 'South Dakota' & toplot$name %in% c('Jones'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'South Dakota' & toplot$name %in% c('Lyman'))]) +toplot$DMA.CODE[which(toplot$state == 'South Dakota' & toplot$name %in% c('Dewey','Campbell'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'South Dakota' & toplot$name %in% c('Corson'))]) +toplot$DMA.CODE[which(toplot$state == 'Iowa' & toplot$name %in% c('Adams'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Iowa' & toplot$name %in% c('Montgomery'))]) +toplot$DMA.CODE[which(toplot$state == 'Missouri' & toplot$name %in% c('Mercer'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Iowa' & toplot$name %in% c('Decatur'))]) +toplot$DMA.CODE[which(toplot$state == 'Missouri' & toplot$name %in% c('Phelps'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Missouri' & toplot$name %in% c('Pulaski'))]) +toplot$DMA.CODE[which(toplot$state == 'Missouri' & toplot$name %in% c('Reynolds'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Missouri' & toplot$name %in% c('Wayne'))]) +toplot$DMA.CODE[which(toplot$state == 'Oklahoma' & toplot$name %in% c('Ottawa'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Kansas' & toplot$name %in% c('Cherokee'))]) +toplot$DMA.CODE[which(toplot$state == 'Kentucky' & toplot$name %in% c('Magoffin'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Kentucky' & toplot$name %in% c('Johnson'))]) +toplot$DMA.CODE[which(toplot$state == 'Pennsylvania' & toplot$name %in% c('Franklin'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Pennsylvania' & toplot$name %in% c('Fulton'))]) +toplot$DMA.CODE[which(toplot$state == 'Ohio' & toplot$name %in% c('Auglaize'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Ohio' & toplot$name %in% c('Shelby'))]) +toplot$DMA.CODE[which(toplot$state == 'Georgia' & toplot$name %in% c('Taylor'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Georgia' & toplot$name %in% c('Marion'))]) +toplot$DMA.CODE[which(toplot$state == 'Illinois' & toplot$name %in% c('Cass'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Illinois' & toplot$name %in% c('Brown'))]) +toplot$DMA.CODE[which(toplot$state == 'Tennessee' & toplot$name %in% c('Wayne'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Alabama' & toplot$name %in% c('Lauderdale'))]) +toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Red River','Camp'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Titus'))]) +toplot$DMA.CODE[which(toplot$state == 'Nebraska' & toplot$name %in% c('Butler','Pawnee'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Nebraska' & toplot$name %in% c('Johnson'))]) +toplot$DMA.CODE[which(toplot$state == 'New Mexico' & toplot$name %in% c('Lea'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Texas' & toplot$name %in% c('Winkler'))]) +toplot$DMA.CODE[which(toplot$state == 'Kansas' & toplot$name %in% c('Morton'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Oklahoma' & toplot$name %in% c('Texas'))]) +toplot$DMA.CODE[which(toplot$state == 'Georgia' & toplot$name %in% c('Seminole'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'Georgia' & toplot$name %in% c('Early'))]) +toplot$DMA.CODE[which(toplot$state == 'Virginia' & toplot$name %in% c('Grayson'))] <- unique(toplot$DMA.CODE[which(toplot$state == 'North Carolina' & toplot$name %in% c('Alleghany'))]) + +as.data.frame(toplot) %>% ungroup() %>% select(state,DMA.CODE) %>% distinct() %>% + group_by(DMA.CODE) %>% summarise(n=n()) -> multiStateDMA + +toplot %>% left_join(multiStateDMA %>% mutate(DMA.CODE,multiState = (n > 1)+0) %>% select(-n)) -> toplot + + + +toplot$treated <- ifelse(toplot$state %in% c('Iowa','New Hampshire','South Carolina','Nevada', + 'Alabama','Arkansas','California','Colorado','Maine', + 'Massachusetts','Minnesota','North Carolina','Oklahoma', + 'Tennessee','Texas','Utah','Vermont','Virginia'),0,1) +comparisons <- as.data.frame(toplot) %>% select(DMA.CODE,multiState,stab,treated) %>% + filter(multiState == 1) %>% + group_by(DMA.CODE) %>% + summarise(IDvar = mean(treated)) %>% + filter(IDvar > 0 & IDvar < 1) + + +pdf('../Figures/figure2.pdf',width = 16,height = 12) +toplot %>% + left_join(comparisons) %>% + mutate(IDvar = ifelse(is.na(IDvar),0,IDvar)) %>% + mutate(treated2 = ifelse(treated == 1 & IDvar > 0,4, + ifelse(treated == 0 & IDvar > 0,3, + ifelse(treated == 1 & IDvar == 0,2,1)))) %>% + mutate(treated2 = ifelse(IDvar > 0,treated2,'drop')) %>% + ggplot() + + geom_sf(aes(fill = factor(treated2),color = treated2),size = .1) + + scale_fill_manual(name = 'Primary Date', + values = c('4' = '#1e1e1e','3' = '#878787', + '2' = 'white','1' = 'white'), + breaks = c('4','3'), + labels = c('4' = 'Post-Outbreak','3' = 'Pre-Outbreak')) + + scale_color_manual(guide = F,values = c('4' = 'white','3' = 'white','drop' = 'grey80'),na.translate = F) + + geom_sf(data = maps$DMA,color = 'black',fill = NA) + + theme_map() +dev.off() + + + +# Figure 3 +p1 <- finalDat %>% + mutate(treat = ifelse(county_March17Cases > 0,1,0), + post = ifelse(date > as.Date('2020-03-10'),'Post March 10','Pre March 17')) %>% + group_by(treat,post) %>% + summarise(outcome = mean(pcttw_sanders,na.rm=T), + sd = sd(pcttw_sanders,na.rm=T)) %>% + ggplot(aes(x = factor(post,levels = c("Pre March 17","Post March 10")),y = outcome, + fill = factor(treat))) + + stat_summary(fun.y = mean,geom = "bar",position = position_dodge(width = .9), + size = 3,alpha = .7) + + scale_fill_manual(name = '',values = c('0' = 'grey80','1' = 'grey30'), + labels = c('0' = 'Insulated on March 17th','1' = 'Exposed on March 17th')) + + theme_ridges() + xlab('Period') + ylab('Sanders Two-Way Vote Share') + +p2 <- finalDat %>% + mutate(post = ifelse(date > as.Date('2020-03-10'),'Post','Pre'), + logcases = log(county_March17Cases+1)) %>% + ggplot(aes(x = logcases,y = pcttw_sanders,color = factor(post,levels = c("Pre","Post")),size = turnout_20,weight = log(turnout_20+1))) + + geom_point(alpha = .6) + + geom_smooth(method = 'lm') + + scale_color_manual(name = "Period",values = c('Post' = 'grey30',"Pre" = "grey70")) + + scale_size_continuous(guide = F) + + theme_ridges() + xlab("March 17 Cases (logged)") + ylab('Sanders Two-Way Vote Share') + + +pdf('../Figures/figure3.pdf',width = 7,height = 5) +grid.arrange(p1 + theme(legend.position = 'bottom'), + p2 + theme(legend.position = 'bottom'),ncol = 2) +dev.off() + + + +# SI Table 1 +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp",'caucus_switch','caucus', + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20") + +maps$county %>% left_join(multiStateDMA %>% mutate(DMA.CODE,multiState = (n > 1)+0) %>% select(-n)) -> maps$county +as.data.frame(maps$county) %>% ungroup() %>% select(FIPS,multiState) %>% + distinct() %>% + left_join(finalDat,by = c("FIPS" = "stcou")) %>% + select(multiState,gsub("sc_|ln_","",covariates),pct_sanders16) -> tocompare + +zeroOne <- function(x) { + return(x > 0 & x < 1) +} + +div100 <- function(x) { + return(x/100) +} +tocompare %>% + mutate(turnout_pct_20 = turnout_pct_20*100) %>% + gather(variable,value,-multiState) %>% + filter(complete.cases(.)) %>% + group_by(multiState,variable) %>% + summarise(value = list(value)) %>% + spread(multiState,value,sep = "_") %>% + group_by(variable) %>% + mutate(p_value = round(t.test(unlist(multiState_0), unlist(multiState_1))$p.value,2), + t_value = round(t.test(unlist(multiState_0), unlist(multiState_1))$statistic,1), + avg_0 = round(mean(unlist(multiState_0),na.rm=T),1), + avg_1 = round(mean(unlist(multiState_1),na.rm=T),1), + sd_0 = round(sd(unlist(multiState_0),na.rm=T),1), + sd_1 = round(sd(unlist(multiState_1),na.rm=T),1)) %>% + select(variable,matches("avg|sd"),p_value,t_value) %>% + arrange(t_value) -> dma_fe_balance +dma_fe_balance$variable <- gsub("_"," ",gsub("CTY_","",dma_fe_balance$variable)) +stargazer(data.frame(dma_fe_balance %>% select(-matches("sd_"))),summary = F,digits = 1,out = '../Tables/SI-table1.tex') diff --git a/29/replication_package/Code/Figure 4.R b/29/replication_package/Code/Figure 4.R new file mode 100644 index 0000000000000000000000000000000000000000..b0f2f0a52c022ff23a4795a2fbe60fe9d4182d14 --- /dev/null +++ b/29/replication_package/Code/Figure 4.R @@ -0,0 +1,53 @@ +# File name: figure4.R +# In: +# - replication_data.RData +# Out: +# - /Figures/figure4.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(ggridges) +rm(list = ls()) +gc() +####################################################################################################################### Loading data +load('../Data/replication_data.RData') + + + + + + + + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + + + +# Figure 4 +finalDat$post <- ifelse(finalDat$date > as.Date('2020-03-10'),1,0) +finalDat$treat <- ifelse(finalDat$DMA_March17Cases > 1,1,0) +summary(tmp <- lmer(as.formula(paste0("pcttw_sanders ~ treat*post + (1|DMA_CODE)")),finalDat))$coefficients +toplot <- data.frame(interaction_plot_continuous(tmp,num_points = 2,pointsplot = T)) + + +pdf('../Figures/figure4.pdf',width = 7,height = 5) +toplot %>% + mutate(x = factor(ifelse(x_2 == 0,'Pre','Post'),levels = c('Pre','Post'))) %>% + ggplot(aes(x = x,y = delta_1))+ + geom_point() + + geom_errorbar(aes(ymin = lb,ymax = ub),width= .1) + + geom_hline(yintercept = 0,linetype = 'dashed') + + xlab("Period") + ylab("Marginal Effect of Exposure") + + theme_ridges() +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Figure 5.R b/29/replication_package/Code/Figure 5.R new file mode 100644 index 0000000000000000000000000000000000000000..f97f68850bf012ebc611aaefa5f1542babde274f --- /dev/null +++ b/29/replication_package/Code/Figure 5.R @@ -0,0 +1,145 @@ +# File name: figure5.R +# In: +# - replication_data.RData +# Out: +# - /Figures/figure5.pdf + + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(ggridges) + +rm(list = ls()) +gc() +####################################################################################################################### Loading data +load('../Data/replication_data.RData') + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + + + + + +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp", + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20") + + + + + + + +# Week-by-week +weeks <- c("2020-02-22","2020-02-29", + "2020-03-03","2020-03-10","2020-03-17","2020-04-07") + +resWkly <- list() +for(y in c("pcttw_sanders")) { + for(d in c("DMA_March10Cases", + "DMA_March17Cases")) { + for(fe in "0") { + + wkly <- wklyBin <- wklyMatch <- wklyWeight <- wklyMatchBin <- wklyWeightBin <- NULL + if(grepl("March",d)) { + wks <- weeks + } else { + wks <- weeks[4:6] + } + for(week in wks) { + if(fe == 'stab' & week == '2020-04-07') { next } + cat(paste0(week,'/',y,'/',d,'/',fe,'\n')) + if(grepl("county",d) & week == "2020-03-01") { next } + if(week < as.Date("2020-03-01")) { + tmp <- finalDat %>% select(y,matches(gsub("sc_|ln_","",d)),DMA_CODE,stab,date,c(covariates,paste0(y,"16"))) %>% filter(date < as.Date(week)) %>% filter(complete.cases(.)) + } else { + tmp <- finalDat %>% select(y,matches(gsub("sc_|ln_","",d)),DMA_CODE,stab,date,c(covariates,paste0(y,"16"))) %>% filter(date == as.Date(week)) %>% filter(complete.cases(.)) + } + tmp$treatBin <- ifelse(tmp[[gsub("sc_|ln_","",d)]] > 0,1,0) + + wkly <- bind_rows(wkly,data.frame(t(summary(felm(as.formula(paste0("scale(",y,") ~ scale(",gsub("sc_","",d),") + ", + paste(unique(c(covariates,paste0(y,"16"))),collapse = "+"), + "| ",fe," | 0 | 0")),tmp))$coefficients[paste0("scale(",gsub("sc_","",d),")"),]),date = week)) + + wklyBin <- bind_rows(wklyBin,data.frame(t(summary(felm(as.formula(paste0("scale(",y,") ~ treatBin + ", + paste(unique(c(covariates,paste0(y,"16"))),collapse = "+"), + "| ",fe," | 0 | 0")),tmp))$coefficients["treatBin",]),date = week)) + + if(length(unique(tmp$treatBin)) == 2) { + m.out <- try(matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), + data = tmp, + method = "nearest", + distance = "mahalanobis")) + if(class(m.out) != "try-error") { + m.data <- match.data(m.out) + wklyMatch <- bind_rows(wklyMatch,data.frame(t(summary(felm(as.formula(paste0("scale(",y,") ~ scale(",gsub("sc_","",d),") + ", + paste(c(covariates,paste0(y,"16")),collapse = " + ")," | ",fe," | 0 | ",fe)), + m.data,weights = m.data$weights))$coefficients[paste0("scale(",gsub("sc_","",d),")"),]),date = week)) + wklyMatchBin <- bind_rows(wklyMatchBin,data.frame(t(summary(felm(as.formula(paste0("scale(",y,") ~ treatBin + ", + paste(c(covariates,paste0(y,"16")),collapse = " + ")," | ",fe," | 0 | ",fe)), + m.data,weights = m.data$weights))$coefficients["treatBin",]),date = week)) + } + + W.out <- try(weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), + data = tmp, estimand = "ATT", method = "cbps")) + + + if(class(W.out) != "try_error") { + wklyWeight <- bind_rows(wklyWeight,data.frame(t(summary(felm(as.formula(paste0("scale(",y,") ~ scale(",gsub("sc_","",d),") + ", + paste(c(covariates,paste0(y,"16")),collapse = " + ")," | ",fe," | 0 | ",fe)), + tmp,weights = W.out$weights))$coefficients[paste0("scale(",gsub("sc_","",d),")"),]),date = week)) + + wklyWeightBin <- bind_rows(wklyWeightBin,data.frame(t(summary(felm(as.formula(paste0("scale(",y,") ~ treatBin + ", + paste(c(covariates,paste0(y,"16")),collapse = " + ")," | ",fe," | 0 | ",fe)), + tmp,weights = W.out$weights))$coefficients["treatBin",]),date = week)) + } + } + } + resWkly[[y]][[d]][[fe]]$basic$cont <- wkly + resWkly[[y]][[d]][[fe]]$basic$bin <- wklyBin + resWkly[[y]][[d]][[fe]]$matching$cont <- wklyMatch + resWkly[[y]][[d]][[fe]]$matching$bin <- wklyMatchBin + resWkly[[y]][[d]][[fe]]$weighting$cont <- wklyWeight + resWkly[[y]][[d]][[fe]]$weighting$bin <- wklyWeightBin + } + } +} + + +pdf('../Figures/figure5.pdf',width = 7,height = 5) +bind_rows(resWkly$pcttw_sanders$DMA_March17Cases$`0`$basic$cont %>% + mutate(type = 'basic', + date = as.Date(date) - .25), + resWkly$pcttw_sanders$DMA_March17Cases$`0`$weighting$cont %>% + mutate(type = 'weighting', + date = as.Date(date) + .25)) %>% + ggplot(aes(x = date,y = Estimate,color = type,fill = type)) + + geom_hline(yintercept = 0,linetype = 'dashed') + + geom_point(size = 1.5) + + geom_rect(aes(xmin = date-.25,ymin = Estimate - 1.96*`Std..Error`, + xmax = date+.25,ymax = Estimate + 1.96*`Std..Error`),alpha = .5,color = NA) + + theme_ridges() + + scale_color_manual(values = c('basic' = 'grey50','weighting' = 'grey40'), + guide = F) + + scale_fill_manual(name = 'Method',values = c('basic' = 'grey70','weighting' = 'grey40'), + labels = c('basic' = 'Unweighted OLS','weighting' = 'CBPS Weights')) + + xlab('Date') + ylab('Coefficient on March 17 Cases') + + theme(legend.position = 'bottom') +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Figure 6, SI1.R b/29/replication_package/Code/Figure 6, SI1.R new file mode 100644 index 0000000000000000000000000000000000000000..f00b71dcc8a2262aa8a93f3db9c9f14ce63e68ae --- /dev/null +++ b/29/replication_package/Code/Figure 6, SI1.R @@ -0,0 +1,221 @@ +# File name: figure6_SIfigure1.R +# In: +# - replication_data.RData +# Out: +# - /Data/Results/tjbalWgtsNEW.RData (saving time re-estimating the weights) +# - /Figures/figure6.pdf +# - /Figures/SI_figure1.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(ggridges) + + +rm(list = ls()) +gc() +####################################################################################################################### Loading data +load('../Data/replication_data.RData') + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + + + + +####################################################################################################################### Preparing variables +Y <- paste0(c("pct_","VAP_","pcttw_"),"sanders") +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp", + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20") + + + + +# SI Figure 1 +set.seed(123) +treatInd <- "March17Cases" +vd <- '2020-03-17' +d <- 'ln_DMA_cases' +est <- 'meanfirst' +treatInd <- paste0("DMA_",treatInd) +forTjbalAnal$treatGroup <- ifelse(forTjbalAnal$voteDate == vd & forTjbalAnal[[treatInd]] > 0,1,0) +forTjbalAnal$treat <- ifelse(forTjbalAnal$treatGroup == 1 & forTjbalAnal$date > as.Date("2020-04-17"),1,0) + +inds <- which(forTjbalAnal$treatGroup == 1) +inds <- unique(forTjbalAnal$stcou[inds]) +ctrlInds <- unique(forTjbalAnal$stcou[-c(which(forTjbalAnal$stcou %in% inds),which(forTjbalAnal$voteDate >= as.Date(vd)))]) + +tmpTjbalAnal <- forTjbalAnal %>% filter(stcou %in% c(inds,ctrlInds)) +tjout <- try(tjbal(data = as.data.frame(tmpTjbalAnal),Y = d,D = "treat",X = unique(c(covariates,"pct_sanders16")), + index = c("stcou","dateNum"),estimator = est,demean = T,vce = "fixed")) + + +toplot <- as.data.frame(tjout$Y.bar) +toplot$date <- seq.Date(from = as.Date("2020-01-23"),to = as.Date("2020-05-01"),length.out = nrow(tjout$Y.bar)) +getwd() +pdf("../Figures/SI_figure1.pdf") +toplot %>% + gather(type,value,-date) %>% + ggplot(aes(x = date,y = value,color = type,size = type,linetype = type,alpha = type)) + + geom_line() + + geom_vline(xintercept = as.Date(unique(finalDat$Date)[which(as.Date(unique(finalDat$Date)) < as.Date("2020-03-17"))]),linetype = "dashed",alpha = .6) + + geom_vline(xintercept = as.Date("2020-03-17"),size = 1.2) + + xlab("Date") + ylab("Number of Cases (logged)") + + annotate(geom = "text",label = c("Iowa Caucuses","New Hampshire","Nevada","South Carolina","Super Tuesday","March 10","March 17"), + x = as.Date(c("2020-02-03","2020-02-11","2020-02-22","2020-02-29", + "2020-03-03","2020-03-10","2020-03-17")),y = Inf,angle = 90,vjust = 1,hjust = 1,size = 3.5,color = "grey30") + + annotate(geom = "text",label = c("Treated","Weighted","Control"), + y = c(7.8,7.5,6.6),x = as.Date("2020-05-02"),angle = 0, + parse = F,hjust = 0,vjust = .3,size = 3.5,color = "grey30") + + scale_linetype_manual(values = c("solid","dotted","solid")) + + scale_size_manual(values = c(1.2,1.2,2.5)) + + scale_color_manual(values = c("red","black","black")) + + scale_alpha_manual(values = c(1,1,.3)) + + xlim(as.Date("2020-01-23"),as.Date("2020-05-10")) + theme_ridges() + + theme(legend.position = "none") + + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), + panel.background = element_blank(), axis.line = element_line(colour = "black")) +dev.off() + + + +# Figure 6 +set.seed(123) +tjBalWgts <- list() +for(vd in c("2020-03-03","2020-03-10","2020-03-17")) { + for(d in c("county_cases")) { + for(est in c("kernel")) { + + if(vd == "2020-03-03") { + treatInd <- "March3Cases" + } else if(vd == "2020-03-10") { + treatInd <- "March10Cases" + } else { + treatInd <- "March17Cases" + } + if(grepl("county",d)) { + treatInd <- paste0("county_",treatInd) + } else { + treatInd <- paste0("DMA_",treatInd) + } + + forTjbalAnal$treatGroup <- ifelse(forTjbalAnal$voteDate == vd & forTjbalAnal[[treatInd]] > 0,1,0) + forTjbalAnal$treat <- ifelse(forTjbalAnal$treatGroup == 1 & forTjbalAnal$date > as.Date("2020-04-17"),1,0) + + inds <- which(forTjbalAnal$treatGroup == 1) + inds <- unique(forTjbalAnal$stcou[inds]) + ctrlInds <- unique(forTjbalAnal$stcou[-c(which(forTjbalAnal$stcou %in% inds),which(forTjbalAnal$voteDate >= as.Date(vd)))]) + + ests <- finalDat %>% select(stcou) + for(i in 1:length(inds)) { + tmpTjbalAnal <- forTjbalAnal %>% filter(stcou %in% c(inds[-i],ctrlInds)) + sink <- capture.output(tjout <- try(tjbal(data = as.data.frame(tmpTjbalAnal),Y = d,D = "treat", + X = unique(c(covariates,"pct_sanders16")),seed = 123, + index = c("stcou","dateNum"),estimator = est,demean = T,vce = "fixed"))) + + if(class(tjout) == "try-error") { next } + tjout$data.wide$w <- tjout$w + ests <- ests %>% left_join(tjout$data.wide %>% select(stcou = unit,w),by = 'stcou') + colnames(ests)[which(colnames(ests) == "w")] <- paste0("w",i) + cat('.') + } + cat('\n') + + tjBalWgts[[vd]][[d]][[est]]$jacknife <- ests + tmpTjbalAnal <- forTjbalAnal %>% filter(stcou %in% c(inds,ctrlInds)) + sink <- capture.output(tjout <- try(tjbal(data = as.data.frame(tmpTjbalAnal),Y = d,D = "treat",X = unique(c(covariates,"pct_sanders16")), + index = c("stcou","dateNum"),estimator = est,demean = T,seed = 123, + vce = "fixed"))) + + if(class(tjout) == "try-error") { next } + tjout$data.wide$w <- tjout$w + tjBalWgts[[vd]][[d]][[est]]$full <- tjout$data.wide %>% select(stcou = unit,w) + } + } +} + +save(tjBalWgts,file = "../Data/Results/tjbalWgtsNEW.RData") +load("../Data/Results/tjbalWgtsNEW.RData") + + + + + + + + + +resTjbal <- list() +for(y in Y) { + for(geo in c("county_","DMA_")) { + for(d in c("March3Cases","March10Cases","March17Cases")) { + if(d == "March3Cases") { + int <- "2020-03-03" + } else if(d == "March10Cases") { + int <- "2020-03-10" + } else { + int <- "2020-03-17" + } + for(balCases in names(tjBalWgts[[int]])) { + for(est in names(tjBalWgts[[int]][[balCases]])) { + + if(is.null(tjBalWgts[[int]][[balCases]][[est]]$full)) { next } + + finalDat %>% left_join(tjBalWgts[[int]][[balCases]][[est]]$full) %>% + left_join(tjBalWgts[[int]][[balCases]][[est]]$jacknife) %>% filter(!is.na(w)) -> tmpAnal + tmpAnal$post <- ifelse(tmpAnal$date == as.Date(int),1,0) + tmpAnal$treatGroup <- ifelse(tmpAnal[[paste0(geo,d)]] > 0,1,0) + tmpAnal$treat <- ifelse(tmpAnal$post == 1 & tmpAnal$treatGroup == 1,1,0) + tmpAnal %>% select(post,treatGroup,treat,date) + + ests <- NULL + for(i in colnames(tmpAnal %>% select(matches("^w\\d")))) { + ests <- c(ests,sum(tmpAnal[[y]]*tmpAnal[[i]],na.rm=T)) + } + resTjbal[[y]][[geo]][[d]][[balCases]][[est]]$bootstrapped <- ests + resTjbal[[y]][[geo]][[d]][[balCases]][[est]]$lmCont <- summary(lm(as.formula(paste0(y," ~ ",balCases)),tmpAnal,weights = abs(tmpAnal$w)))$coefficients + resTjbal[[y]][[geo]][[d]][[balCases]][[est]]$lmBin <- summary(lm(as.formula(paste0(y," ~ treat")),tmpAnal,weights = abs(tmpAnal$w)))$coefficients + } + } + } + } +} + + +toplot <- NULL +for(period in names(resTjbal$pcttw_sanders$DMA_)) { + toplot <- bind_rows(toplot, + data.frame(bs = resTjbal$pcttw_sanders$county_[[period]]$county_cases$kernel$bootstrapped, + period = period)) +} + + + + +# Figure 6: +pdf('../Figures/figure6.pdf',width = 7,height = 5) +toplot %>% + mutate(period = factor(gsub('Cases','', + gsub('March','March ',period)),levels = rev(c('March 3','March 10','March 17')))) %>% + ggplot(aes(x = bs,y = period)) + + geom_density_ridges(alpha = .7,color = 'black') + + theme_ridges() + + geom_vline(xintercept = 0,linetype = 'dashed') + + xlab('ATT of Exposure on Sanders Support') + ylab('Outbreak Date') +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Figure 7, SI2, SI17.R b/29/replication_package/Code/Figure 7, SI2, SI17.R new file mode 100644 index 0000000000000000000000000000000000000000..57d6a8781ce05517bd5bc209c2edb49eafc4ef6d --- /dev/null +++ b/29/replication_package/Code/Figure 7, SI2, SI17.R @@ -0,0 +1,125 @@ +# File name: figure7_SIfigure2_SIfigure17.R +# In: +# - /Data/gtrends_data.RData: DMA-level data on google searches for "coronavirus" linked with DMA-level cases and deaths +# - /Data/mobility_data.RData: county-level data on physical mobility linked with county-level cases and deaths +# - /Data/pew/biden_sanders_ideo_feb_march_PEW.csv: Pew survey data on public's placement of Sanders and Biden on an ideological scale +# Out: +# - /Figures/figure7.pdf +# - /Figures/SI_figure2.pdf +# - /Figures/SI_figure17.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(ggridges) + +rm(list = ls()) +gc() + +# Figure 7 +load('../Data/gtrends_data.RData') +coefs <- NULL +for(day in as.character(unique(gtrends_cases$date))[5:95]) { + tmp <- summary(lmer(hits ~ log(cases+1) + (1|stab),gtrends_cases %>% filter(date == as.Date(day))))$coefficients + if(nrow(tmp) == 1) { next } + txttmp <- unique(trimws(gsub("coronavirus|the","",queries[[day]]$value))) + if(any(txttmp == "")) { + txttmp <- txttmp[-which(txttmp == "")] + } + txttmp <- txttmp[1:3] + if(any(txttmp == "DGSGsymptoms")) { + txttmp <- ifelse(txttmp == "symptoms",'"symptoms"',paste0('phantom("',txttmp,'")')) + txttmp <- paste(txttmp,collapse = " ") + txttmp <- gsub(' "symptoms"',' * "symptoms"',txttmp) + txttmp <- gsub('"symptoms" ','"symptoms" * ',txttmp) + txttmp <- gsub('"\\) phantom\\("', ' ',txttmp) + } else { + txttmp <- paste(txttmp,collapse = " ") + } + tq <- txttmp + + coefs <- bind_rows(coefs,data.frame(t(tmp[2,]),date = as.Date(day),topQ = tq,stringsAsFactors = F)) +} + +pdf("../figures/figure7.pdf",width = 7,height = 5) +coefs %>% + ggplot(aes(x = date,y = Estimate)) + + geom_point() + + geom_errorbar(aes(ymin = Estimate - 2*Std..Error,ymax = Estimate + 2*Std..Error)) + + theme_bw() + + geom_hline(yintercept = 0) + + theme_bw() + + geom_vline(xintercept = as.Date(c("2020-02-03","2020-02-11","2020-02-22","2020-02-29", + "2020-03-03","2020-03-10","2020-03-17")),linetype = "dashed",alpha = .3) + + annotate(geom = "text",label = c("IA","NH","NV","SC","SupTues","Mar 10th","AZ, FL, IL"), + x = as.Date(c("2020-02-03","2020-02-11","2020-02-22","2020-02-29", + "2020-03-03","2020-03-10","2020-03-17")),y = -Inf,angle = 90,vjust = 1,hjust = 0) + + theme_ridges() + + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), + panel.background = element_blank(), axis.line = element_line(colour = "black")) + xlab("Date") + ylab("Coefficient on Exposure") + + annotate(geom = "text",label = coefs$topQ,y = coefs$Estimate + 2*coefs$Std..Error + 1,x = coefs$date,angle = 90, + parse = F,hjust = 0,vjust = .3,size = 2,color = "grey30") + + ylim(c(-10,45)) +dev.off() + + + +# SI Figure 2 +load('../Data/mobility_data.RData') + +dma_coefs <- cty_coefs <- NULL +for(week in as.character(unique(mobility_cases$weeks))[-13]) { + tmp <- summary(felm(raw ~ log(cases+1) | stab | 0 | stab,mobility_cases %>% filter(weeks == as.Date(week))))$coefficients[1,1:3] + names(tmp) <- c("Estimate","Std..Error","tstat") + cty_coefs <- bind_rows(cty_coefs, + data.frame(t(tmp),date = as.Date(week),stringsAsFactors = F)) +} + +pdf("../figures/SI_figure2.pdf",width= 7,height = 5) +cty_coefs %>% + ggplot(aes(x = date,y = Estimate)) + + geom_point(position = position_dodge(width = 4)) + + geom_errorbar(aes(ymin = Estimate - 2*Std..Error, + ymax = Estimate + 2*Std..Error),width = 1) + + geom_hline(yintercept = 0) + + theme_bw() + + geom_vline(xintercept = as.Date(c("2020-02-03","2020-02-11","2020-02-22","2020-02-29", + "2020-03-03","2020-03-10","2020-03-17")),linetype = "dashed",alpha = .5) + + annotate(geom = "text",label = c("IA","NH","NV","SC","SupTues","Mar 10th","AZ, FL, IL"), + x = as.Date(c("2020-02-03","2020-02-11","2020-02-22","2020-02-29", + "2020-03-03","2020-03-10","2020-03-17")),y = Inf,angle = 90,vjust = 1,hjust = 1) + + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), + panel.background = element_blank(), axis.line = element_line(colour = "black")) + xlab("Date") + ylab("Coefficient on Exposure") + + theme_ridges() +dev.off() + + + + + + + +# SI Figure 17 +toplot <- read.csv('../Data/pew/biden_sanders_ideo_feb_march_PEW.csv',stringsAsFactors = F) + +pdf('../figures/SI_figure17.pdf',width = 8,height = 4) +toplot %>% + mutate_at(vars(matches('\\.|Refused|Moderate')),function(x) as.numeric(gsub('%','',x))) %>% + gather(key,value,-Group,-Candidate) %>% + filter(!grepl('Refused|Not\\.sure',key)) %>% + mutate(key = factor(gsub('\\.','\n',key),levels = c('Very\nliberal','Mostly\nliberal','Slightly\nliberal', + 'Moderate','Slightly\nconservative','Mostly\nconservative','Very\nconservative'))) %>% + filter(grepl('liberal dem',tolower(Group))) %>% + ggplot(aes(x = key,y = value,group = Candidate,fill = Candidate)) + + geom_bar(stat = 'identity',position= position_dodge(.8),alpha = .6) + + ylab('% Agreeing') + xlab('Candidate Ideology') + + scale_fill_manual(name = '',values = c('Biden' = 'grey40','Sanders' = 'grey70')) + + theme_ridges() + + theme(legend.position = 'bottom') +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Figure 8, SI19.R b/29/replication_package/Code/Figure 8, SI19.R new file mode 100644 index 0000000000000000000000000000000000000000..9122ec951c61b8820a6c3619c5d3a0eb3db43617 --- /dev/null +++ b/29/replication_package/Code/Figure 8, SI19.R @@ -0,0 +1,95 @@ +# File name: figure8_SIfigure19.R +# In: +# - /Data/france_data.RData: Data on 2020 municipal elections in France, linked with local-level cases and deaths +# Out: +# - /Figures/figure8.pdf +# - /Figures/SI_figure19.pdf + + +require(lfe) +require(ggridges) +require(tidyverse) +require(gridExtra) +rm(list =ls()) +gc() +####################################################################################################################### Loading functions +source('./helper_functions.R') + + +load('../Data/france_data.RData') + +# Figure 8 +p1 <- toanal %>% + mutate(mainstream = ifelse(mainstream == 0,'Non-Mainstream','Mainstream'), + period = factor(ifelse(date == as.Date('2020-03-15'),'March Elections','June Elections'), + levels = c('March Elections','June Elections'))) %>% + group_by(mainstream,period) %>% + summarise(votes = mean(votes)) %>% + ungroup() %>% + filter(complete.cases(.)) %>% + ggplot(aes(x = period,y = votes,fill = factor(mainstream))) + + stat_summary(fun.y = mean,geom = "bar",position = position_dodge(width = .9), + size = 3,alpha = .7) + + scale_fill_manual(name = '',values = c('Mainstream' = 'grey80','Non-Mainstream' = 'grey30')) + + theme_ridges() + xlab('Period') + ylab('Aggregate Vote Share') + +p2 <- toanal %>% + mutate(mainstream = ifelse(mainstream == 0,'Non-Mainstream','Mainstream'), + period = factor(ifelse(date == as.Date('2020-03-15'),'March Elections','June Elections'), + levels = c('March Elections','June Elections')), + logcases = log(deaths+1)) %>% + filter(!is.na(period)) %>% + ggplot(aes(x = logcases,y = votes,color = mainstream)) + + geom_point(alpha = .7,size = 2) + + geom_smooth(method = 'lm') + + scale_color_manual(name = "",values = c('Mainstream' = 'grey80',"Non-Mainstream" = "grey30")) + + theme_ridges() + xlab("Deaths (logged)") + ylab('Aggregate Vote Share') + +pdf('../figures/figure8.pdf',width = 7,height = 4) +grid.arrange(p1 + theme(legend.position = 'bottom'), + p2 + theme(legend.position = 'bottom'),ncol = 2) +dev.off() + + + +# SI Figure 19 +toanal$post <- ifelse(toanal$date == '2020-03-15',0,1) + +toanal$antiEst <- (toanal$mainstream - 1)^2 +summary(mod1 <- felm(votes ~ antiEst*post | dpt_code | 0 | dpt_code,toanal)) +summary(mod2 <- felm(votes ~ antiEst*log(deaths+1) | post + dpt_code | 0 | dpt_code,toanal)) + +toplot <- data.frame(interaction_plot_continuous(mod1,plot = T,pointsplot = T,colr = 'black',alph = 200,num_points = 2, + xlabel = "Election Wave",ylabel = 'Marginal Coefficient of Mainstream')) %>% + mutate(type = 'Temporal') + +toplot <- bind_rows(toplot,data.frame(interaction_plot_continuous(mod2,plot = T,pointsplot = T, + colr = 'black',alph = 200,num_points = 20, + xlabel = "Election Wave",ylabel = 'Marginal Coefficient of Mainstream')) %>% + mutate(type = 'Geographic')) + + + +p1 <- toplot %>% + filter(type == 'Temporal') %>% + mutate(x = factor(ifelse(x_2 == 0,'March Elections','June Elections'),levels = c('March Elections','June Elections'))) %>% + ggplot(aes(x = x,y = delta_1)) + + geom_point() + + geom_errorbar(aes(ymin = lb,ymax = ub),width = .1) + + geom_hline(yintercept = 0,linetype = 'dashed') + + ylab('Margnial Coefficient on Non-Mainstream') + xlab('') + + theme_ridges() + + ggtitle('Temporal Variation') +p2 <- toplot %>% + filter(type == 'Geographic') %>% + ggplot(aes(x = x_2,y = delta_1)) + + geom_point() + + geom_errorbar(aes(ymin = lb,ymax = ub),width = .1) + + geom_hline(yintercept = 0,linetype = 'dashed') + + ylab('Margnial Coefficient on Non-Mainstream') + xlab('Logged Deaths') + + theme_ridges() + + ggtitle('Geographic Variation') + +pdf('../Figures/SI_figure19.pdf',width = 8,height = 4) +grid.arrange(p1,p2,ncol = 2) +dev.off() diff --git a/29/replication_package/Code/Figure SI11, SI12, SI15, SI16.R b/29/replication_package/Code/Figure SI11, SI12, SI15, SI16.R new file mode 100644 index 0000000000000000000000000000000000000000..1fb916c6a10e1f8857606be8c2e0e13b4169fe96 --- /dev/null +++ b/29/replication_package/Code/Figure SI11, SI12, SI15, SI16.R @@ -0,0 +1,115 @@ +# File name: SIfigure11_SIfigure12_SIfigure15_SIfigure16.R +# In: +# - nationscape_prepped.RData: Nationscape survey data merged with NYT covid data, aggregated to the congressional district level +# Out: +# - /Figures/SI_figure11.pdf +# - /Figures/SI_figure12.pdf +# - /Figures/SI_figure15.pdf +# - /Figures/SI_figure16.pdf + + + +rm(list = ls()) +gc() +require(tidyverse) +require(stargazer) +require(lubridate) +require(ggridges) +require(lfe) + + + +####################################################################################################################### Loading data +load('../Data/nationscape_data.RData') + + + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + +# SI Figure 11 +pdf('../Figures/SI_figure11.pdf',width = 7,height = 5) +forAnal %>% + filter(dateMo < as.Date('2020-07-01') & dateMo > as.Date('2019-07-01')) %>% + group_by(stcd,dateMo,exposedMean) %>% + summarise(ideoM = mean(economy_better,na.rm=T)) %>% + ggplot(aes(x = ideoM,y = fct_rev(factor(dateMo)),group = paste(dateMo,exposedMean), + fill = paste(dateMo,exposedMean))) + + geom_density_ridges(alpha = .6,color = 'white',quantile_lines = T,quantiles = 2) + + scale_fill_cyclical( + breaks = c("2019-08-01 0", "2019-08-01 1"), + labels = c(`2019-08-01 0` = "Insulated", `2019-08-01 1` = "Exposed"), + values = rev(c("#000000", "#b0b0b0", "#000000", "#b0b0b0")), + name = "", guide = "legend" + ) + + theme_ridges() + + xlab("Economic Evaluation") + + ylab("") + + scale_x_continuous(limits = c(1,3),breaks = 1:3,labels = c('Improved','The Same','Worse')) +dev.off() + +# SI Figure 12 +forAnal %>% + filter(dateMo < as.Date('2020-07-01') & dateMo > as.Date('2019-07-01')) %>% + group_by(stcd,dateWk,dateMo,exposedMean) %>% + summarise(econ = mean(economy_better,na.rm=T)) %>% + mutate(post = ifelse(dateMo > as.Date('2020-02-01'),1,0)) -> forDID + +summary(mEcon <- felm(scale(econ) ~ exposedMean*post | 0 | 0 | stcd,forDID %>% filter(dateMo < as.Date('2020-04-01')))) +toplot <- data.frame(interaction_plot_continuous(mEcon,pointsplot = T,num_points = 2,plot = T)) + +pdf('../Figures/SI_figure12.pdf',width = 7,height = 4) +toplot %>% + mutate(x_2 = factor(ifelse(x_2 == 0,'Pre-March','March'),levels = c('Pre-March','March'))) %>% + ggplot(aes(x = x_2,y = delta_1)) + + geom_point() + + geom_errorbar(aes(ymin = lb,ymax = ub),width = .1) + + geom_hline(yintercept = 0,linetype = 'dashed') + + theme_ridges() + + xlab('Period') + ylab('Effect of Covid Exposure') +dev.off() + + + +# SI Figure 15 +(pSanders <- forAnal %>% + mutate(sanders = (cand_favorability_sanders - 5)*-1) %>% #ifelse(cand_favorability_sanders < 3,1,0)) %>% + filter(dateMo < as.Date('2020-05-01') & dateMo > as.Date('2019-07-01')) %>% + group_by(stcd,dateMo,exposedMean) %>% + summarise(ideoM = mean(sanders,na.rm=T)) %>% + ggplot(aes(x = ideoM,y = fct_rev(factor(dateMo)),group = paste(dateMo,exposedMean), + fill = paste(dateMo,exposedMean))) + + geom_density_ridges(alpha = .6,color = 'white',quantile_lines = T,quantiles = 2) + + scale_fill_cyclical( + breaks = c("2019-08-01 0", "2019-08-01 1"), + labels = c(`2019-08-01 0` = "Insulated", `2019-08-01 1` = "Exposed"), + values = rev(c("#000000", "#b0b0b0", "#000000", "#b0b0b0")), + name = "", guide = "legend" + ) + + theme_ridges() + + xlab("Sanders Approval") + + ylab("") + + scale_x_continuous(breaks = 1:4,labels = c('Very\nunfavorable','Somewhat\nunfavorable','Somewhat\nfavorable','Very\nfavorable'))) + +pdf('../Figures/SI_figure15.pdf',width = 7,height = 5) +print(pSanders) +dev.off() + +# SI Figure 16 +pdf('../Figures/SI_figure16.pdf',width = 8,height = 5) +forAnal %>% + mutate(sanders = (cand_favorability_sanders - 5)*-1) %>% #ifelse(cand_favorability_sanders < 3,1,0)) %>% + filter(dateWk %in% as.Date(c('2020-02-02','2020-02-09','2020-02-16','2020-02-23','2020-03-01','2020-03-08','2020-03-15','2020-03-22','2020-03-29'))) %>% + group_by(stcd,dateWk) %>% + summarise(sanders = mean(sanders,na.rm=T), + cases = log(mean(casesSum,na.rm=T)+1)) %>% + ggplot(aes(x = cases,y = sanders)) + + geom_point() + + geom_smooth(method = 'lm') + + facet_wrap(~dateWk) + + theme_ridges() + + xlab('Logged Cases') + ylab('Sanders Approval') +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Figure SI3, SI4, SI5.R b/29/replication_package/Code/Figure SI3, SI4, SI5.R new file mode 100644 index 0000000000000000000000000000000000000000..9102244c795cb5a4540d703e52e86bdcf069fb16 --- /dev/null +++ b/29/replication_package/Code/Figure SI3, SI4, SI5.R @@ -0,0 +1,167 @@ +# File name: SIfigure3_SIfigure4_SIfigure_5.R +# In: +# - replication_data.RData +# - +# Out: +# - /Figures/SI_figure3.pdf +# - /Figures/SI_figure4.pdf +# - /Figures/SI_figure5.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(gridExtra) +require(ggridges) +require(ggrepel) + +rm(list = ls()) +gc() + + + + +####################################################################################################################### Loading data +load(paste0('../Data/Results/SI-data.RData')) ## SI_robust_prep.R script which is designed to run on a computing cluster for speed. + + + + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + + +# SI Figure 3 +toplot <- NULL +for(post in c('2020-03-03','2020-03-10','2020-03-17')) { + for(mod in c('basic','matching','weighting')) { + toplot <- bind_rows(toplot,data.frame(est = resSI$pcttw_sanders$DMA_$March17Cases$DMA_CODE$`2020-03-01`[[post]]$felm[[mod]]$plac$did, + post = factor(ifelse(post == '2020-03-03','Control: February\nTreated: March 3rd', + ifelse(post == '2020-03-10','Control: February\nTreated: March 10th', + 'Control: February\nTreated: March 17th')), + levels = c('Control: February\nTreated: March 3rd', + 'Control: February\nTreated: March 10th', + 'Control: February\nTreated: March 17th')), + model = Hmisc::capitalize(mod),stringsAsFactors = F)) + } +} + + +pdf('../Figures/SI_figure3.pdf',width = 8,height = 5) +toplot %>% + ggplot(aes(x = est,y = factor(model,levels = rev(c('Basic','Matching','Weighting'))))) + + geom_vline(xintercept = 0,linetype = 'dashed') + + geom_density_ridges(alpha = .4,color = 'white') + + facet_wrap(~post) + ylab('Method') + xlab("Bootstrapped Estimates") + + theme_ridges() + + theme( + strip.text.x = element_text( + size = 10, color = "black", face = "bold",hjust = 0,vjust = .5 + ), + strip.background = element_rect( + color="white", fill="white", size=0, linetype="solid" + ) + ) +dev.off() + + + + +# SI Figure 4 +toplot <- NULL +for(pre in c('2020-03-01','2020-03-03','2020-03-10','2020-03-17')) { + for(post in c('2020-03-01','2020-03-03','2020-03-10','2020-03-17')) { + for(mod in c('basic','weighting','matching')) { + tmp <- resSI$pcttw_sanders$DMA_$March10Cases$DMA_CODE[[pre]][[post]]$felm[[mod]]$bin['treat',] + if(is.null(tmp)) { next } + tmp <- data.frame(t(tmp)) + colnames(tmp) <- c('est','se','tstat','pval') + tmp$pre <- pre + tmp$post <- post + tmp$mod <- mod + toplot <- bind_rows(toplot,tmp) + } + } +} + + +pdf('../Figures/SI_figure4.pdf',width = 8,height = 5) +toplot %>% + mutate(post = factor(gsub('03-03','ST', + gsub('03-01','Feb', + gsub('2020-','',post))),levels = c('Feb','ST','03-10','03-17')), + pre = factor(paste0('Pre Election: ',gsub('03-03','Super Tuesday', + gsub('03-01','February', + gsub('2020-','',pre)))), + levels = paste0('Pre Election: ',c('February','Super Tuesday','03-10','03-17')))) %>% + ggplot(aes(x = post,y = est,shape = mod)) + + geom_point(position = position_dodge(width = .2),size = 2,alpha = .7) + + geom_errorbar(aes(ymin = est-2*se,ymax = est+2*se),width = .2, + position = position_dodge(width = .2),alpha = .4) + + geom_hline(yintercept = 0,linetype = 'dashed') + + facet_wrap(~pre) + + scale_shape_manual(name = 'Model', + values = c('basic' = 19,'matching' = 17,'weighting' = 15), + labels = c('Basic','Matching','Weighting')) + + theme_ridges() + + theme(legend.position = 'bottom') + + xlab('Post Election') + ylab('Effect of DMA Exposure') +dev.off() + + + + +# SI Figure 5 +toplot <- NULL +for(pre in c('2020-03-01','2020-03-03','2020-03-10','2020-03-17')) { + for(post in c('2020-03-01','2020-03-03','2020-03-10','2020-03-17')) { + for(mod in c('basic','weighting','matching')) { + tmp <- resSI$pcttw_sanders$DMA_$March17Cases$`0`[[pre]][[post]]$felm[[mod]]$did$mfx + if(is.null(tmp)) { next } + tmp <- data.frame(tmp) + tmp$pre <- pre + tmp$post <- post + tmp$mod <- mod + toplot <- bind_rows(toplot,tmp) + } + } +} + + +pdf('../Figures/SI_figure5.pdf',width = 8,height = 5) +toplot %>% + filter(pre < post, + mod == 'weighting') %>% + mutate(x_2 = ifelse(x_2 == 0,gsub('2020-','',pre),gsub('2020-','',post)), + sig = ifelse(grepl('\\*',est),'Sig','Insig')) %>% + mutate(x_2 = factor(ifelse(x_2 == '03-01','Feb', + ifelse(x_2 == '03-03','ST',x_2)), + levels = c('Feb','ST','03-10','03-17'))) %>% + mutate(pre = factor(paste0('Pre: ',ifelse(pre == '2020-03-01','February', + ifelse(pre == '2020-03-03','Super Tuesday',pre))), + levels = paste0('Pre: ',c('February','Super Tuesday','2020-03-10','2020-03-17'))), + post = factor(paste0('Post: ',ifelse(post == '2020-03-01','February', + ifelse(post == '2020-03-03','Super Tuesday',post))), + levels = paste0('Post: ',c('February','Super Tuesday','2020-03-10','2020-03-17')))) %>% + ggplot(aes(x = x_2,y = delta_1,color = sig)) + + geom_point(position = position_dodge(width = .2),size = 2) + + geom_errorbar(aes(ymin = lb,ymax = ub),width = .1,size = 1, + position = position_dodge(width = .2)) + + geom_hline(yintercept = 0,linetype = 'dashed') + + facet_wrap(~pre+post,scales = 'free',ncol = 3) + + scale_color_manual(name = 'Sig.',values = c('Sig' = 'black','Insig' = 'grey50')) + + scale_linetype_manual(name = 'Model', + values = c('basic' = 'dotdash','matching' = 'dashed','weighting' = 'solid')) + + scale_shape_manual(name = 'Model', + values = c('basic' = 19,'matching' = 17,'weighting' = 15)) + + theme_ridges() + xlab('Comparison Periods') + ylab('Marginal Effect of Exposure') + + theme(legend.position = 'bottom') +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Figure SI6, SI7, SI8, SI9, SI10.R b/29/replication_package/Code/Figure SI6, SI7, SI8, SI9, SI10.R new file mode 100644 index 0000000000000000000000000000000000000000..917eea1c9e02238784f67d3c82ca36d9914d5ff1 --- /dev/null +++ b/29/replication_package/Code/Figure SI6, SI7, SI8, SI9, SI10.R @@ -0,0 +1,348 @@ +# File name: SIfigure6_SIfigure7_SIfigure8_SIfigure9_SIfigure10.R +# In: +# - replication_data.RData +# Out: +# - /Figures/SI_figure6.pdf +# - /Figures/SI_figure7.pdf +# - /Figures/SI_figure8.pdf +# - /Figures/SI_figure9.pdf +# - /Figures/SI_figure10.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(gridExtra) +require(ggridges) +require(ggrepel) + +rm(list = ls()) +gc() + + + + +####################################################################################################################### Loading data +load('../Data/replication_data.RData') + + + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + + + + + +####################################################################################################################### Preparing variables +Y <- paste0(c("pct_","VAP_","pcttw_"),"sanders") +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp",'caucus_switch','caucus', + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20") + + + + + + +####################################################################################################################### Looping across specifications +finalDat$sc_turnout_pct_chg <- scale(finalDat$turnout_pct_chg) +finalDat$sc_VAP_turnout_20 <- scale(finalDat$VAP_turnout_20) + +Y <- c("sc_turnout_pct_20","sc_turnout_pct_chg","sc_VAP_turnout_20") +resTurnout <- list() +for(y in Y) { + for(d in D) { + for(fe in FE) { + for(m in c("sc_CTY_LT30yo","sc_CTY_60Up","sc_CTY_Unem_rate_pop_16_over","sc_CTY_Old_age_dep_ratio","sc_CTY_POPPCT_RURAL","sc_CTY_Manufactur","sc_CTY_LTHS","sc_CTY_CollUp")) { + resTurnout[[y]][[d]][[fe]][[m]]$felm$coefs <- summary(tmp <- felm(as.formula(paste0(y," ~ ",d,"*",m," + ", + paste(c(covariates)[-which(c(covariates) %in% c("sc_CTY_LT30yo","sc_CTY_60Up","sc_turnout_pct_20"))],collapse = "+")," | ",fe," | 0 | ",fe)),finalDat))$coefficients + resTurnout[[y]][[d]][[fe]][[m]]$felm$mfx <- interaction_plot_continuous(tmp) + if(fe != "0") { + resTurnout[[y]][[d]][[fe]][[m]]$lmer$coefs <- summary(tmp <- lmer(as.formula(paste0(y," ~ ",d,"*",m," + ", + paste(c(covariates)[-which(c(covariates) %in% c("sc_CTY_LT30yo","sc_CTY_60Up","sc_turnout_pct_20"))],collapse = "+")," + (1| ",fe,")")),finalDat))$coefficients + resTurnout[[y]][[d]][[fe]][[m]]$lmer$mfx <- interaction_plot_continuous(tmp) + + } + + } + } + } +} + + +p1 <- data.frame(resTurnout$sc_turnout_pct_20$sc_DMA_cases$DMA_CODE$sc_CTY_60Up$felm$mfx) %>% + ggplot(aes(x = x_2,y = delta_1)) + + geom_point() + + geom_errorbar(aes(ymin = lb,ymax = ub),width = .1) + + geom_hline(yintercept = 0,linetype = 'dashed') + + xlab(expression(Younger %<->% Older)) + + ylab('MFX of Exposure on Turnout') + + theme_ridges() + + ggtitle(label = '',subtitle = '% of county 60 years or older') + +p2 <- data.frame(resTurnout$sc_turnout_pct_20$sc_DMA_cases$DMA_CODE$sc_CTY_LT30yo$felm$mfx) %>% + ggplot(aes(x = x_2,y = delta_1)) + + geom_point() + + geom_errorbar(aes(ymin = lb,ymax = ub),width = .1) + + geom_hline(yintercept = 0,linetype = 'dashed') + + xlab(expression(Older %<->% Younger)) + + ylab('MFX of Exposure on Turnout') + + theme_ridges() + + ggtitle(label = '',subtitle = '% of county 30 years or younger') + + +# SI Figure 6: Turnout and age +pdf('../Figures/SI_figure6.pdf',width = 8,height = 5) +grid.arrange(p1,p2,ncol = 2) +dev.off() + + + +# SI Figure 7 +pdf('../Figures/SI_figure7.pdf',width = 8,height = 5) +finalDat %>% + group_by(date,stab) %>% + summarise(pct_sanders16 = mean(pct_sanders16,na.rm=T), + turnout_pct_20 = mean(turnout_pct_20*100,na.rm=T)) %>% + ggplot(aes(x = date,y = turnout_pct_20,size = pct_sanders16,label = stab)) + + geom_point(alpha = .3) + + geom_text_repel(size = 4) + + theme_ridges() + + xlab('Date') + ylab('Turnout 2020 (%)') + + scale_size(name = 'Sanders 2016 Vote Share (%)') + + theme(legend.position = 'bottom') +dev.off() + + +# SI Figure 8 +p1 <- finalDat %>% + filter(date %in% as.Date(c('2020-03-03', + '2020-03-10', + '2020-03-17'))) %>% + mutate(turnout_pct_20 = turnout_pct_20*100) %>% + ggplot(aes(x = pct_sanders16,y = turnout_pct_20)) + + geom_point() + + geom_smooth() + + theme_ridges() + + xlab('Sanders 2016 Vote Share (%)') + + ylab('Turnout 2020 (%)') + ylim(c(0,50)) + + ggtitle(label = '',subtitle = 'March Data') + +p2 <- finalDat %>% + filter(date < as.Date('2020-03-03')) %>% + mutate(turnout_pct_20 = turnout_pct_20*100) %>% + ggplot(aes(x = pct_sanders16,y = turnout_pct_20)) + + geom_point() + + geom_smooth() + + theme_ridges() + + xlab('Sanders 2016 Vote Share (%)') + + ylab('Turnout 2020 (%)') + ylim(c(0,50)) + + ggtitle(label = '',subtitle = 'Pre-March Data') + +pdf('../Figures/SI_figure8.pdf',width = 9,height = 5) +grid.arrange(p2,p1,ncol = 2) +dev.off() + + + + +# SI Figure 9 +finalDat$post <- ifelse(finalDat$date > as.Date('2020-02-29'),1,0) +toplot <- data.frame(summary(felm(as.formula(paste0("turnout_pct_20 ~ scale(pct_sanders16)*factor(date) + ", + paste(covariates[c(1:2,5:17)],collapse = '+'),'| 0 | 0 | 0')),finalDat))$coefficients) +colnames(toplot) <- c('est','se','tstat','pval') +toplot$vars <- rownames(toplot) +rownames(toplot) <- NULL + + +toplot %>% + filter(grepl(':factor',vars)) %>% + mutate(date = as.Date(gsub('scale.*?date\\)','',vars))) %>% + ggplot(aes(x = date,y = est)) + + geom_point() + + geom_errorbar(aes(ymin = est - 2*se,ymax = est+2*se)) + + geom_hline(yintercept = 0,linetype = 'dashed') + + +finalDat$dateTmp <- as.Date(ifelse(finalDat$Date %in% as.Date(c('2020-02-11','2020-02-22')),as.Date('2020-02-22'),finalDat$Date),origin = '1970-01-01') +toplot <- NULL +for(d in unique(finalDat$Date)) { + if(nrow(finalDat %>% filter(Date == d)) < 50) { + covs <- covariates[c(2,6,9,15)] + } else { + covs <- covariates[c(2,6,9,15)] + } + tmp <- data.frame(t(summary(felm(as.formula(paste0("scale(turnout_pct_20) ~ scale(pct_sanders16) + ", + paste(covs,collapse = '+'),'| 0 | 0 | 0')),finalDat %>% + filter(Date == d)))$coefficients[2,])) + colnames(tmp) <- c('est','se','tstat','pval') + tmp$date <- as.Date(d,origin = '1970-01-01') + toplot <- bind_rows(toplot,tmp) +} + + +labs <- finalDat %>% + select(stab,Date) %>% distinct() +toplot$lab <- NA +for(d in unique(toplot$date)) { + toplot$lab[which(toplot$date == d)] <- paste(unique(labs$stab[which(labs$Date == d)])[order(unique(labs$stab[which(labs$Date == d)]))],collapse = '\n') +} + + +pdf('../Figures/SI_figure9.pdf',width = 8,height = 5) +toplot %>% + filter(date < as.Date('2020-04-15')) %>% + ggplot(aes(x = date,y = est,label = lab,color = ifelse(lab == 'SC','SC','black'))) + + geom_point() + + geom_errorbar(aes(ymin = est - 2*se,ymax = est+2*se),width = .5) + + geom_hline(yintercept = 0,linetype = 'dashed') + + theme_ridges() + + xlab('Election Date') + ylab('Relationship between Sanders 2016 and Turnout') + + scale_color_manual(values = c('SC' = 'red','black' = 'black')) + + geom_text_repel(size = 3,hjust = 0,vjust = .5,alpha = .8) + + theme(legend.position = 'none') +dev.off() + + + + + + + + + + + + + + +# SI Figure 10 +set.seed(123) +Y <- c('pct_sanders16') + +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","stab") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp",'caucus_switch','caucus', + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English", + "sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20") + + +resRegs <- resBal <- resTabs <- list() +for(y in Y) { + for(d in D[c(1:3)]) { + + for(fe in FE) { + stars <- list() + for(dateThresh in c("2020-01-01","2020-03-01")) { + if(dateThresh == '2020-03-01') { + covs <- covariates[-which(covariates == 'caucus')] + } else { + covs <- covariates + } + if(!is.null(resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$felm$cont)) { next } + finalDat$treatBin <- ifelse(finalDat[[gsub("sc_|ln_","",d)]] > 1,1,0) + foranal.weight <- finalDat %>% select(y,d,treatBin,gsub("sc_|ln_","",d),DMA_CODE,date,stab,covs) %>% + filter(complete.cases(.),date >= as.Date(dateThresh)) + + m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(covs,collapse = " + "))), + data = foranal.weight, + method = "nearest", + distance = "mahalanobis") + + m.data <- match.data(m.out) + W.out <- weightit(formula(paste0("treatBin ~ ",paste(covs,collapse = " + "))), + data = foranal.weight, estimand = "ATT", method = "cbps") + + # Balance tables + balt.pre <- bal.tab(formula(paste0("treatBin ~ ",paste(covs,collapse = " + "))), + data = foranal.weight, estimand = "ATT",m.threshold = .05) + + balt.post <- bal.tab(W.out, m.threshold = .05, disp.v.ratio = TRUE) + unm <- data.frame(Covs = rownames(balt.pre$Balance), + balt.pre$Balance %>% mutate(Diff_Unm = round(Diff.Un,2), + Bal_Test_Unm = M.Threshold.Un)) %>% + select(Covs,Diff_Unm,Bal_Test_Unm) + + match <- data.frame(Covs = rownames(balt.post$Balance), + balt.post$Balance %>% mutate(Diff_Match = round(Diff.Adj,2), + Bal_Test_Match = M.Threshold)) %>% + select(Covs,Diff_Match,Bal_Test_Match) + + + # Basic + resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$felm$cont <- summary(stars$cont[[paste0(dateThresh,"_1")]] <- felm(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),finalDat %>% filter(date >= as.Date(dateThresh))))$coefficients + resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$felm$bin <- summary(stars$bin[[paste0(dateThresh,"_1")]] <- felm(as.formula(paste0("scale(",y,") ~ treatBin + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),finalDat %>% filter(date >= as.Date(dateThresh))))$coefficients + + # Matching + resRegs[[y]][[d]][[fe]][[dateThresh]]$matching$felm$cont <- summary(stars$cont[[paste0(dateThresh,"_2")]] <- felm(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients + resRegs[[y]][[d]][[fe]][[dateThresh]]$matching$felm$bin <- summary(stars$bin[[paste0(dateThresh,"_2")]] <- felm(as.formula(paste0("scale(",y,") ~ treatBin + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients + + # Weighting + resRegs[[y]][[d]][[fe]][[dateThresh]]$weighting$felm$cont <- summary(stars$cont[[paste0(dateThresh,"_3")]] <- felm(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),foranal.weight,weights = W.out$weights))$coefficients + resRegs[[y]][[d]][[fe]][[dateThresh]]$weighting$felm$bin <- summary(stars$bin[[paste0(dateThresh,"_3")]] <- felm(as.formula(paste0("scale(",y,") ~ treatBin + ",paste(c(covs),collapse = " + ")," | ",fe," | 0 | ",fe)),foranal.weight,weights = W.out$weights))$coefficients + + if(fe != "0") { + resRegs[[y]][[d]][[fe]][[dateThresh]]$basic$lmer <- summary(lmer(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," + (1| ",fe,")")),finalDat %>% filter(date >= as.Date(dateThresh))))$coefficients + resRegs[[y]][[d]][[fe]][[dateThresh]]$matching$lmer <- summary(lmer(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," + (1| ",fe,")")),m.data,weights = m.data$weights))$coefficients + resRegs[[y]][[d]][[fe]][[dateThresh]]$weighting$lmer <- summary(lmer(as.formula(paste0("scale(",y,") ~ ",d," + ",paste(c(covs),collapse = " + ")," + (1| ",fe,")")),foranal.weight,weights = W.out$weights))$coefficients + } + } + } + cat(y,"\n") + } +} + + +toplot <- NULL +for(fe in names(resRegs$pct_sanders16$sc_DMA_cases)) { + for(mod in c('basic','matching','weighting')) { + for(meas in c('bin','cont')) { + tmp <- resRegs$pct_sanders16$sc_DMA_cases[[fe]]$`2020-01-01`[[mod]]$felm[[meas]][2,] + if(is.null(tmp)) { next } + tmp <- data.frame(t(tmp)) + colnames(tmp) <- c('est','se','tstat','pval') + tmp$fe <- fe + tmp$mod <- mod + tmp$meas <- meas + toplot <- bind_rows(toplot,tmp) + } + } +} + + +pdf('../Figures/SI_figure10.pdf',width = 8,height = 5) +toplot %>% + filter(meas != 'cont') %>% + mutate(fe = factor(ifelse(fe == 0,'None', + ifelse(fe == 'DMA_CODE','DMA','State')),levels = c('None','DMA','State'))) %>% + ggplot(aes(x = fe,y = est,color = mod)) + + geom_point(position = position_dodge(width = .2)) + + geom_errorbar(aes(ymin = est - 2*se,ymax = est+2*se),width = .1, + position = position_dodge(width = .2)) + + geom_hline(yintercept = 0,linetype = 'dashed') + + scale_color_manual(name = 'Model',values = c('basic' = 'grey70', + 'matching' = 'grey40', + 'weighting' = 'black')) + + xlab('Fixed Effect') + ylab('Effect of Covid Exposure on Bernie 2016') + + theme_ridges() +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/LOG/log_Figure 2, 3, Table SI1.txt b/29/replication_package/Code/LOG/log_Figure 2, 3, Table SI1.txt new file mode 100644 index 0000000000000000000000000000000000000000..57f976b37007e486aed4f6316e3e74220aefe10a --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure 2, 3, Table SI1.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac9be1e8f990ed341bee6e7d18f48117865ad78bda8e09611524ee337a8c700d +size 17430 diff --git a/29/replication_package/Code/LOG/log_Figure 4.txt b/29/replication_package/Code/LOG/log_Figure 4.txt new file mode 100644 index 0000000000000000000000000000000000000000..477ad445877c9c21a1c1286f5b6e8be573a31e11 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure 4.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0cc2dad199e651b3b18aeac4e0872d2227f1e3fd5fdcf0bbb5d97f3bf79f78b4 +size 1906 diff --git a/29/replication_package/Code/LOG/log_Figure 5.txt b/29/replication_package/Code/LOG/log_Figure 5.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4c6cbac326bf727320c516959738643c74cb669 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure 5.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a0e002d85754f3ce56b44690a936549dac1aab32673faeab1d2b5117b07148c3 +size 9547 diff --git a/29/replication_package/Code/LOG/log_Figure 6, SI1.txt b/29/replication_package/Code/LOG/log_Figure 6, SI1.txt new file mode 100644 index 0000000000000000000000000000000000000000..be9aa033142f9108a8daac9ad0d9de7746c95929 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure 6, SI1.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d85f5f426954e63384f029e51fc8bad3a0fa568e2e96c823912ac5ec3ce3b53e +size 25431 diff --git a/29/replication_package/Code/LOG/log_Figure 7, SI2, SI17.txt b/29/replication_package/Code/LOG/log_Figure 7, SI2, SI17.txt new file mode 100644 index 0000000000000000000000000000000000000000..2ae9c9027a7e3b5ee346033a17dbc1f2cdce5202 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure 7, SI2, SI17.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c7e9bea12b383efed75d618abbad1fe8b0fc400af78494907a990126013633a +size 6005 diff --git a/29/replication_package/Code/LOG/log_Figure 8, SI19.txt b/29/replication_package/Code/LOG/log_Figure 8, SI19.txt new file mode 100644 index 0000000000000000000000000000000000000000..17e78781b79347cb16ba80b1e4e12caec6338b9a --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure 8, SI19.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b7f087095576a80be99dd9bef648177e9769b00e426d980ac0cdb581e51e7eb4 +size 6385 diff --git a/29/replication_package/Code/LOG/log_Figure SI11, SI12, SI15, SI16.txt b/29/replication_package/Code/LOG/log_Figure SI11, SI12, SI15, SI16.txt new file mode 100644 index 0000000000000000000000000000000000000000..c23cc590bbb9a99001ecc887ef3c552ae6f53df0 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure SI11, SI12, SI15, SI16.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d32418d31e1abf7167109380c2c6a5dbd91821699226279b298073d65c5fe2b +size 6545 diff --git a/29/replication_package/Code/LOG/log_Figure SI3, SI4, SI5.txt b/29/replication_package/Code/LOG/log_Figure SI3, SI4, SI5.txt new file mode 100644 index 0000000000000000000000000000000000000000..cf41ae36dd5572cff38aa1b000860d09b2402548 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure SI3, SI4, SI5.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1e920a955b865e9923d5e317755c889c2ee835f017e75b054ada4534cd8668d9 +size 7395 diff --git a/29/replication_package/Code/LOG/log_Figure SI6, SI7, SI8, SI9, SI10.txt b/29/replication_package/Code/LOG/log_Figure SI6, SI7, SI8, SI9, SI10.txt new file mode 100644 index 0000000000000000000000000000000000000000..ea45e856b373a0149fad74d8c2b0f4e92b6d14e0 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Figure SI6, SI7, SI8, SI9, SI10.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60754321979b0db06d5eb13c89490b8d40c981341013b6ca81f43f839770694b +size 16586 diff --git a/29/replication_package/Code/LOG/log_SI_robust_prep.txt b/29/replication_package/Code/LOG/log_SI_robust_prep.txt new file mode 100644 index 0000000000000000000000000000000000000000..2fe8d06e378b75d9d87c7277c4812be1dec8f398 --- /dev/null +++ b/29/replication_package/Code/LOG/log_SI_robust_prep.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:360ac1137e6197ce131aa3056d3a23d609bf8eb2ace11b14b7c2f0e6abfeaf17 +size 13355 diff --git a/29/replication_package/Code/LOG/log_Table 1, SI3, SI4, SI5, Figure SI13, SI14.txt b/29/replication_package/Code/LOG/log_Table 1, SI3, SI4, SI5, Figure SI13, SI14.txt new file mode 100644 index 0000000000000000000000000000000000000000..df0d8ac1006bb4e338bf1d4328fbeb0adeef95d5 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Table 1, SI3, SI4, SI5, Figure SI13, SI14.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00d48e16d2aa71185aefc9e5f5b1a4d5c67d1168f975854b424970d30cd49210 +size 63166 diff --git a/29/replication_package/Code/LOG/log_Table 2.txt b/29/replication_package/Code/LOG/log_Table 2.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0a046806ec893f40074f3854965bcd8c0ebcc55 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Table 2.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72a6b1087b7f0f5c2195a5cfecb70dc38aeee23444503dccbca5eb450c7e72d5 +size 21934 diff --git a/29/replication_package/Code/LOG/log_Table 3, Figure SI18.txt b/29/replication_package/Code/LOG/log_Table 3, Figure SI18.txt new file mode 100644 index 0000000000000000000000000000000000000000..05e3f8622ce490a84ea49112d5c5daeac62d9c73 --- /dev/null +++ b/29/replication_package/Code/LOG/log_Table 3, Figure SI18.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95ac713d5fe9453df1f122c481132f92d7f51dd38bf7d4df8fa6d6f6b3bd6917 +size 18257 diff --git a/29/replication_package/Code/LOG/log_zzSI_robust_prep.txt b/29/replication_package/Code/LOG/log_zzSI_robust_prep.txt new file mode 100644 index 0000000000000000000000000000000000000000..c365bcc32059bee2070837db15a0feec63373dab --- /dev/null +++ b/29/replication_package/Code/LOG/log_zzSI_robust_prep.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ef673370a716a15af5283f51187228e456867c6b8a528d6c480942e97c6c5ff0 +size 18906 diff --git a/29/replication_package/Code/MASTER.R b/29/replication_package/Code/MASTER.R new file mode 100644 index 0000000000000000000000000000000000000000..470882196cdca0fe0beb0decb7fe0926c7c742a8 --- /dev/null +++ b/29/replication_package/Code/MASTER.R @@ -0,0 +1,13 @@ +# Master script +for(f in list.files('./')) { + if(grepl('helper_functions|MASTER|LOG',f)) { next } + if(file.exists(paste0('./LOG/log_',gsub('.R','.txt',f)))) { next } + # stop() + con <- file(paste0('./LOG/log_',gsub('.R','.txt',f))) + cat(f,'\n') + sink(con,append = TRUE) + sink(con,append = TRUE,type = 'message') + source(f,echo = T,max.deparse.length = 10000) + sink() + sink(type = 'message') +} diff --git a/29/replication_package/Code/Table 1, SI3, SI4, SI5, Figure SI13, SI14.R b/29/replication_package/Code/Table 1, SI3, SI4, SI5, Figure SI13, SI14.R new file mode 100644 index 0000000000000000000000000000000000000000..3bdb48319be86c46b12a4113db5b1594c4e994a6 --- /dev/null +++ b/29/replication_package/Code/Table 1, SI3, SI4, SI5, Figure SI13, SI14.R @@ -0,0 +1,349 @@ +# File name: table1_SItable3_SItable5_SItable4_SIfigure13_SIfigure14.R +# In: +# - replication_data.RData +# Out: +# - /Tables/table1.tex +# - /Tables/SI-table3.tex +# - /Figures/SI_figure13.pdf +# - /Tables/SI-table4.tex +# - /Tables/SI-table5.tex +# - /Figures/SI_figure14.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) + +rm(list = ls()) +gc() +####################################################################################################################### Loading data +load('../Data/replication_data.RData') + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + + + +####################################################################################################################### Preparing variables +Y <- c('pct_sanders16',paste0(c("pct_","VAP_","pcttw_"),"sanders")) +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp", + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20",'caucus_switch','caucus') + + + +# Function for generating matched data + weighted data +wgtMatchFun <- function(dat,formMatch,formWgt,matchMethod = 'nearest',wgtMethod = 'cbps') { + m.out <- matchit(formula = formula(formMatch), + data = dat, + method = matchMethod, + distance = "mahalanobis") + + m.data <- match.data(m.out) + W.out <- weightit(formula = formula(formWgt), + data = dat, + estimand = "ATT", + method = wgtMethod) + + # Balance tables + balt.pre <- bal.tab(formula(formWgt), + data = dat, + estimand = "ATT", + m.threshold = .05) + + balt.post <- bal.tab(W.out, m.threshold = .05, disp.v.ratio = TRUE) + unm <- data.frame(Covs = gsub('_$','',rownames(balt.pre$Balance)), + balt.pre$Balance %>% + mutate(Diff_Unm = round(Diff.Un,2), + Bal_Test_Unm = M.Threshold.Un)) %>% + select(Covs,Diff_Unm,Bal_Test_Unm) + + match <- data.frame(Covs = rownames(balt.post$Balance), + balt.post$Balance %>% mutate(Diff_Match = round(Diff.Adj,2), + Bal_Test_Match = M.Threshold)) %>% + select(Covs,Diff_Match,Bal_Test_Match) + + + balTab <- match %>% left_join(unm) %>% select(Covs,Diff_Unm,Bal_Test_Unm,Diff_Match,Bal_Test_Match) + balPlot <- qqprep(x = m.out) + + return(list(balTab = balTab, + m.data = m.data, + W.out = W.out, + dat = dat, + balPlot = balPlot)) +} + + +set.seed(123) +finalDat$treatBin <- ifelse(finalDat$DMA_cases > 1,1,0) + +# Full Sample Regressions: Nearest neighbor + CBPS +summary(mFullRaw <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + finalDat)) + + +foranal.weight <- finalDat %>% + select(pcttw_sanders,DMA_cases,treatBin,DMA_CODE,date,stab,covariates,pcttw_sanders16) %>% + filter(complete.cases(.)) + +fullPrepped <- wgtMatchFun(dat = foranal.weight, + formMatch = paste0('treatBin ~ ',paste(covariates,collapse = " + ")), + formWgt = paste0('treatBin ~ ',paste(covariates,collapse = " + ")), + matchMethod = 'nearest', + wgtMethod = 'cbps') + +summary(mFullMatch <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + fullPrepped$m.data,weights = fullPrepped$m.data$weights)) + + +summary(mFullWgt <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + fullPrepped$dat,weights = fullPrepped$W.out$weights)) + + +# March + April Regressions +foranal.weight <- finalDat %>% + select(pcttw_sanders,DMA_cases,treatBin, + DMA_CODE,date,stab,covariates, + pcttw_sanders16) %>% + filter(complete.cases(.), + date >= as.Date('2020-03-01')) + +covariates <- covariates[-which(covariates == 'caucus')] + +marPrepped <- wgtMatchFun(dat = foranal.weight, + formMatch = paste0('treatBin ~ ',paste(covariates,collapse = " + ")), + formWgt = paste0('treatBin ~ ',paste(covariates,collapse = " + ")), + matchMethod = 'nearest', + wgtMethod = 'cbps') + +summary(mMarRaw <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + ")," | DMA_CODE | 0 | DMA_CODE")), + finalDat %>% filter(date >= as.Date("2020-03-01")))) + +summary(mMarMatch <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + ")," | DMA_CODE | 0 | DMA_CODE")), + marPrepped$m.data,weights = marPrepped$m.data$weights)) + + +summary(mMarWgt <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + ")," | DMA_CODE | 0 | DMA_CODE")), + marPrepped$dat,weights = marPrepped$W.out$weights)) + + +# Table 1 +covars <- rownames(mFullRaw$coefficients) +labs <- gsub('Treatbin','Exposure Dummy',gsub('Turnout pct 20','Turnout 2020',gsub('Pcttw sanders16','Sanders 2016',gsub('Caucus$','Caucus dummy',gsub("Lths","LTHS",gsub("Collup","Coll. Up",gsub("Md inc HH","Med HH Inc",gsub("Sc ","",gsub(" or african american|band$","",Hmisc::capitalize(trimws(gsub("manufactur","manufacturing",gsub("hher|hhs","HH",gsub("labor force part rate","LFPR",gsub("bachelor s","bachelor's",gsub("age 18 64|pop 16 over|hh$|poppct","",gsub("\\_"," ",gsub("^sc_|^.*cty\\_","",tolower(covars))))))))))))))))))) + +prepTable <- function(tab,keeps = c('Exposure Dummy','Turnout 2020','Sanders 2016', + 'Caucus dummy','Caucus switch'),tops = 1:14,bottoms = (length(tab) - 8):length(tab)) { + inds <- NULL + for(keep in keeps) { + tmpInds <- which(grepl(keep,tab)) + for(i in tmpInds) { + inds <- c(inds,i:(i+2)) + } + } + inds <- unique(c(tops,inds,bottoms)) + + return(tab[inds]) +} + +tex <- stargazer(mFullRaw,mFullMatch,mFullWgt, + mMarRaw,mMarMatch,mMarWgt, + keep.stat = c("n","rsq"), + star.cutoffs = c(.1,.05,.01,.001), + star.char = c('\\dag','*','**','***'), + covariate.labels = labs) + +cat(paste(prepTable(tex,keeps = c('Exposure Dummy','Turnout 2020','Sanders 2016', + 'Caucus switch','Caucus dummy')), + collapse = '\n'),file = '../Tables/table1.tex') + + + +# SI Table 3 +stargazer(marPrepped$balTab,summary = F,out = '../Tables/SI-table3.tex') + + + +# SI Figure 13 +toplot <- fullPrepped$balPlot$toplot +# rr <- marPrepped$balPlot$rr + +dist2d <- function(x,y) { + m <- cbind(c(-1,-1),c(x,y)) + abs(det(m))/sqrt(sum(c(-1,-1)^2)) +} +vdist2d <- Vectorize(dist2d,vectorize.args = c("x","y")) +toplot$type <- as.character(toplot$type) +toplot$cov <- as.character(toplot$cov) +toplot <- toplot %>% bind_rows(toplot %>% group_by(cov) %>% summarise(x = min(x,y),y = min(x,y)), + toplot %>% group_by(cov) %>% summarise(x = max(x,y),y = max(x,y))) + + +toplot$cov <- Hmisc::capitalize(tolower(trimws(gsub("Manufactur","Manufacturing",gsub("Labor Force Part Rate","LFPR",gsub("hher|hhs","HH",gsub("Bachelor s","Bachelor's",gsub("_"," ",gsub("CTY_|AGE_18_64|pop_16_over|hh$|POPPCT","",toplot$cov))))))))) +toplot %>% group_by(type,cov) %>% + summarise(eucdist = mean(vdist2d(x = x,y= y))) %>% + filter(!is.na(type)) -> sum.euc + + + +pdf('../Figures/SI_figure13.pdf',width = 7,height = 7) +toplot %>% + filter(!grepl('caucus',tolower(cov))) %>% + ggplot(aes(x = x,y = y,color = factor(type,levels = c("Raw","Matched")), + text = paste0(type,"\nEuc Dist = ",round(vdist2d(x = x,y = y),2)))) + + geom_point(alpha = .3,size = .5) + + geom_abline() + + geom_abline(aes(intercept = (rrlb - rrub) * 0.1,slope = 1),linetype = "dashed") + + geom_abline(aes(intercept = -(rrlb - rrub) * 0.1,slope = 1),linetype = "dashed") + + theme_bw() + + xlab("Control") + ylab("Treated") + + theme(legend.position = "bottom") + + facet_wrap(~cov,scales = "free") + + scale_color_discrete("",na.translate = F) + + guides(color = guide_legend(override.aes = list(size = 5,alpha = 1))) +dev.off() + + + + + + + + +# SI Tables 4-5 and Figure 14 +# Full Sample Regressions: CEM + optweights +summary(mFullRaw <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + finalDat)) + + +foranal.weight <- finalDat %>% select(pcttw_sanders,DMA_cases,treatBin,DMA_CODE,date,stab,covariates,pcttw_sanders16) %>% filter(complete.cases(.)) +fullPrepped <- wgtMatchFun(dat = foranal.weight, + formMatch = paste0('treatBin ~ ',paste(covariates[c(4,2,10,12,7,13)],collapse = " + ")), + formWgt = paste0('treatBin ~ ',paste(covariates,collapse = " + ")), + matchMethod = 'cem', + wgtMethod = 'optweight') + +summary(mFullMatch <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + fullPrepped$m.data,weights = fullPrepped$m.data$weights)) + + +summary(mFullWgt <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covariates,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + fullPrepped$dat,weights = fullPrepped$W.out$weights)) + + +# March + April Regressions +foranal.weight <- finalDat %>% + select(pcttw_sanders,DMA_cases,treatBin, + DMA_CODE,date,stab,covariates, + pcttw_sanders16) %>% + filter(complete.cases(.), + date >= as.Date('2020-03-01')) + +covs <- covariates[-which(grepl('caucus',covariates))] + +marPrepped <- wgtMatchFun(dat = foranal.weight, + formMatch = paste0('treatBin ~ ',paste(covs[c(4,2,10,12,7,13)],collapse = " + ")), # CEM fails with the full set of covariates. See SI page 13-15 for discussion. + formWgt = paste0('treatBin ~ ',paste(covs,collapse = " + ")), + matchMethod = 'cem', + wgtMethod = 'optweight') + +summary(mMarRaw <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covs,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + finalDat %>% filter(date >= as.Date("2020-03-01")))) + +summary(mMarMatch <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covs,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + marPrepped$m.data,weights = marPrepped$m.data$weights)) + + +summary(mMarWgt <- felm(as.formula(paste0("scale(pcttw_sanders) ~ treatBin + ", + paste(c(covs,"pcttw_sanders16"),collapse = " + "), + " | DMA_CODE | 0 | DMA_CODE")), + marPrepped$dat,weights = marPrepped$W.out$weights)) + + +# SI Table 4 +stargazer(fullPrepped$balTab,summary = F,out = '../Tables/SI-table4.tex') + + +# SI Table 5 +covars <- rownames(mFullRaw$coefficients) +labs <- gsub('Treatbin','Exposure Dummy',gsub('Turnout pct 20','Turnout 2020',gsub('Pcttw sander16','Sanders 2016',gsub('Caucus$','Caucus dummy',gsub("Lths","LTHS",gsub("Collup","Coll. Up",gsub("Md inc HH","Med HH Inc",gsub("Sc ","",gsub(" or african american|band$","",Hmisc::capitalize(trimws(gsub("manufactur","manufacturing",gsub("hher|hhs","HH",gsub("labor force part rate","LFPR",gsub("bachelor s","bachelor's",gsub("age 18 64|pop 16 over|hh$|poppct","",gsub("\\_"," ",gsub("^sc_|^.*cty\\_","",tolower(covars))))))))))))))))))) + +stargazer(mFullRaw,mFullMatch,mFullWgt, + mMarRaw,mMarMatch,mMarWgt, + keep.stat = c("n","rsq"), + star.cutoffs = c(.1,.05,.01,.001), + star.char = c('\\dag','*','**','***'), + covariate.labels = labs,out = '../Tables/SI-table5.tex') + + + + +# SI Figure 14 +toplot <- fullPrepped$balPlot$toplot + +dist2d <- function(x,y) { + m <- cbind(c(-1,-1),c(x,y)) + abs(det(m))/sqrt(sum(c(-1,-1)^2)) +} +vdist2d <- Vectorize(dist2d,vectorize.args = c("x","y")) +toplot$type <- as.character(toplot$type) +toplot$cov <- as.character(toplot$cov) +toplot <- toplot %>% bind_rows(toplot %>% group_by(cov) %>% summarise(x = min(x,y),y = min(x,y)), + toplot %>% group_by(cov) %>% summarise(x = max(x,y),y = max(x,y))) + + +toplot$cov <- Hmisc::capitalize(tolower(trimws(gsub("Manufactur","Manufacturing",gsub("Labor Force Part Rate","LFPR",gsub("hher|hhs","HH",gsub("Bachelor s","Bachelor's",gsub("_"," ",gsub("CTY_|AGE_18_64|pop_16_over|hh$|POPPCT","",toplot$cov))))))))) +toplot %>% group_by(type,cov) %>% + summarise(eucdist = mean(vdist2d(x = x,y= y))) %>% + filter(!is.na(type)) -> sum.euc + + + +pdf('../Figures/SI_figure14.pdf',width = 7,height = 5) +toplot %>% + filter(!grepl('caucus',tolower(cov))) %>% + ggplot(aes(x = x,y = y,color = factor(type,levels = c("Raw","Matched")),text = paste0(type,"\nEuc Dist = ",round(vdist2d(x = x,y = y),2)))) + + geom_point(alpha = .3,size = .5) + + geom_abline() + + geom_abline(aes(intercept = (rrlb - rrub) * 0.1,slope = 1),linetype = "dashed") + + geom_abline(aes(intercept = -(rrlb - rrub) * 0.1,slope = 1),linetype = "dashed") + + theme_bw() + + xlab("Control") + ylab("Treated") + + theme(legend.position = "bottom") + + facet_wrap(~cov,scales = "free") + + scale_color_discrete("",na.translate = F) + + guides(color = guide_legend(override.aes = list(size = 5,alpha = 1))) +dev.off() \ No newline at end of file diff --git a/29/replication_package/Code/Table 2.R b/29/replication_package/Code/Table 2.R new file mode 100644 index 0000000000000000000000000000000000000000..91756f6ae4e40f200fdb354406f9a3742ce9b8cb --- /dev/null +++ b/29/replication_package/Code/Table 2.R @@ -0,0 +1,82 @@ +# File name: table2.R +# In: +# - /Data/survey_experiment_data.RData +# Out: +# - /Tables/table2.tex + +rm(list = ls()) +gc() +require(tidyverse) + +load('../Data/survey_experiment_data.RData') +# Basic test: Does pessimistic treatment increase support for mainstream candidate? +summary(main <- lm(scale(y) ~ z + factor(polAge) + factor(polOcc) + factor(polPlat) + + factor(age) + factor(sex) + factor(hisp) + white + black + asian + factor(pid), + foranal %>% + filter(duration > 180) %>% + mutate(sex = factor(sex,levels = c("Neither male nor female describes me accurately OR prefer not to say","Female","Male")), + polPlat = factor(polPlat,levels = c("none","hlth","educ")), + pid = factor(pid,levels = c("Strong Democrat","Democrat","Lean Democrat","Independent","Lean Republican","Republican","Strong Republican")), + covid_self = factor(covid_self,levels = c("No","Maybe","Yes")), + covid_pers = factor(covid_pers,levels = c("No","Maybe","Yes"))))) + +summary(biv <- lm(yBin ~ z, + foranal %>% + filter(duration > 0) %>% + mutate(sex = factor(sex,levels = c("Neither male nor female describes me accurately OR prefer not to say","Female","Male")), + polPlat = factor(polPlat,levels = c("none","hlth","educ")), + pid = factor(pid,levels = c("Strong Democrat","Democrat","Lean Democrat","Independent","Lean Republican","Republican","Strong Republican")), + covid_self = factor(covid_self,levels = c("No","Maybe","Yes")), + covid_pers = factor(covid_pers,levels = c("No","Maybe","Yes"))))) + +summary(ind <- lm(yBin ~ z + + factor(age) + factor(sex) + factor(hisp) + white + black + asian + factor(pid), + foranal %>% + filter(duration > 0) %>% + mutate(sex = factor(sex,levels = c("Neither male nor female describes me accurately OR prefer not to say","Female","Male")), + polPlat = factor(polPlat,levels = c("none","hlth","educ")), + pid = factor(pid,levels = c("Strong Democrat","Democrat","Lean Democrat","Independent","Lean Republican","Republican","Strong Republican")), + covid_self = factor(covid_self,levels = c("No","Maybe","Yes")), + covid_pers = factor(covid_pers,levels = c("No","Maybe","Yes"))))) + +summary(indcov <- lm(yBin ~ z + + factor(age) + factor(sex) + factor(hisp) + white + black + asian + factor(pid), + foranal %>% + filter(duration > 0) %>% + mutate(sex = factor(sex,levels = c("Neither male nor female describes me accurately OR prefer not to say","Female","Male")), + polPlat = factor(polPlat,levels = c("none","hlth","educ")), + pid = factor(pid,levels = c("Strong Democrat","Democrat","Lean Democrat","Independent","Lean Republican","Republican","Strong Republican")), + covid_self = factor(covid_self,levels = c("No","Maybe","Yes")), + covid_pers = factor(covid_pers,levels = c("No","Maybe","Yes"))))) + +summary(full <- lm(yBin ~ z + + factor(age) + factor(sex) + factor(hisp) + white + black + asian + factor(pid) + + factor(polAge) + factor(polOcc) + factor(polPlat), + foranal %>% + filter(duration > 0) %>% + mutate(sex = factor(sex,levels = c("Neither male nor female describes me accurately OR prefer not to say","Female","Male")), + polPlat = factor(polPlat,levels = c("none","hlth","educ")), + pid = factor(pid,levels = c("Strong Democrat","Democrat","Lean Democrat","Independent","Lean Republican","Republican","Strong Republican")), + covid_self = factor(covid_self,levels = c("No","Maybe","Yes")), + covid_pers = factor(covid_pers,levels = c("No","Maybe","Yes"))))) + + + +summary(attentive <- lm(yBin ~ z + + factor(age) + factor(sex) + factor(hisp) + white + black + asian + factor(pid) + + factor(polAge) + factor(polOcc) + factor(polPlat), + foranal %>% + filter(duration > 150) %>% + mutate(sex = factor(sex,levels = c("Neither male nor female describes me accurately OR prefer not to say","Female","Male")), + polPlat = factor(polPlat,levels = c("none","hlth","educ")), + pid = factor(pid,levels = c("Strong Democrat","Democrat","Lean Democrat","Independent","Lean Republican","Republican","Strong Republican")), + covid_self = factor(covid_self,levels = c("No","Maybe","Yes")), + covid_pers = factor(covid_pers,levels = c("No","Maybe","Yes"))))) +require(stargazer) +stargazer(biv,ind,full,attentive,keep.stat = c("n","rsq"),keep = "pid|covid|z", + covariate.labels = c("Anxiety Prime","Democrat","Lean Dem","Independent","Lean GOP","Republican","Strong GOP"), + star.char = c('\\dag','*','**','***'), + star.cutoffs = c(.1,.05,.01,.001), + out = "../Tables/table2.tex") + + diff --git a/29/replication_package/Code/Table 3, Figure SI18.R b/29/replication_package/Code/Table 3, Figure SI18.R new file mode 100644 index 0000000000000000000000000000000000000000..503b3216ea384fe551455042ad9b232b6eb46cbb --- /dev/null +++ b/29/replication_package/Code/Table 3, Figure SI18.R @@ -0,0 +1,109 @@ +# File name: table3_SIfigure18.R +# In: +# - /Data/primary_data.RData: Primary election results for the house of representatives, linked with district-level cases and deaths +# Out: +# - /Tables/table3.tex +# - /Figures/SI_figure18.pdf + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(tidyverse) +require(stargazer) +require(gridExtra) +require(ggridges) +require(ggrepel) + +rm(list = ls()) +gc() + + +load('../Data/primary_data.RData') + +# Table 3 +summary(mVScaseEXT <- felm(voteSh ~ extreme*log(casesSum+1) | stcd | 0 | stcd,toAnal)) +summary(mVScaseJST <- felm(voteSh ~ justice*log(casesSum+1) | stcd | 0 | stcd,toAnal)) +summary(mVScaseTEA <- felm(voteSh ~ tea*log(casesSum+1) | stcd | 0 | stcd,toAnal)) + +summary(mVSdthEXT <- felm(voteSh ~ extreme*log(deathsSum+1) | stcd | 0 | stcd,toAnal)) +summary(mVSdthJST <- felm(voteSh ~ justice*log(deathsSum+1) | stcd | 0 | stcd,toAnal)) +summary(mVSdthTEA <- felm(voteSh ~ tea*log(deathsSum+1) | stcd | 0 | stcd,toAnal)) + +summary(mVTcaseEXT <- felm(log(votes+1) ~ extreme*log(casesSum+1) + log(totVotes+1) | stcd | 0 | stcd,toAnal %>% filter(votes != 0))) +summary(mVTcaseJST <- felm(log(votes+1) ~ justice*log(casesSum+1) + log(totVotes+1) | stcd | 0 | stcd,toAnal %>% filter(votes != 0))) +summary(mVTcaseTEA <- felm(log(votes+1) ~ tea*log(casesSum+1) + log(totVotes+1) | stcd | 0 | stcd,toAnal %>% filter(votes != 0))) + +summary(mVTdthEXT <- felm(log(votes+1) ~ extreme*log(deathsSum+1) + log(totVotes+1) | stcd | 0 | stcd,toAnal %>% filter(votes != 0))) +summary(mVTdthJST <- felm(log(votes+1) ~ justice*log(deathsSum+1) + log(totVotes+1) | stcd | 0 | stcd,toAnal %>% filter(votes != 0))) +summary(mVTdthTEA <- felm(log(votes+1) ~ tea*log(deathsSum+1) + log(totVotes+1) | stcd | 0 | stcd,toAnal %>% filter(votes != 0))) + +regs <- list() +for(m in objects(pattern = '^mVScase')) { + regs[[m]] <- get(m) + rownames(regs[[m]]$coefficients) <- rownames(regs[[m]]$beta) <- gsub(':',' X ', + gsub('tea|justice|extreme','Anti-Est.', + gsub('log\\(deathsSum \\+ 1\\)','Deaths (ln)', + gsub('log\\(casesSum \\+ 1\\)','Cases (ln)', + gsub('log\\(totVotes \\+ 1\\)','Total Votes (ln)',rownames(regs[[m]]$coefficients)))))) +} + +stargazer(regs,keep.stat = c('n','rsq'), + star.char = c('\\dag','*','**','***'), + star.cutoffs = c(.1,.05,.01,.001), + add.lines = list(c('District FE','Y','Y','Y','Y')), out = '../Tables/table3.tex') + +# SI Figure 18 +toplot <- toAnal %>% + filter(date < as.Date('2020-11-01'), + votes > 0) + +toplot$lab <- NA +for(d in unique(toplot$date)) { + toplot$lab[which(toplot$date == d)] <- paste(unique(toplot$stab[which(toplot$date == d)]),collapse = '\n') +} + + + +p1 <- toplot %>% + ggplot(aes(x = date,y = voteSh,color = factor(extreme),size = casesSum,weight = log(casesSum+1), + alpha = factor(extreme), + label = lab)) + + geom_jitter(width = 0) + + geom_smooth(method = 'lm') + + geom_text(data = toplot %>% + group_by(date) %>% + slice(1) %>% + filter(!stab %in% c('HI','TN')) %>% + ungroup() %>% + mutate(voteSh = 1.01, + date = date - 3), + size = 2.5,hjust = 0,vjust = 0,color = 'black',alpha = .8) + + theme_ridges() + + scale_color_manual(name = 'Type',values = c(`0` = 'grey60',`1` = 'black'),label = c('Mainstream','Extreme')) + + scale_alpha_manual(guide = F,values = c(`0` = .15,`1` = .6)) + + scale_size_continuous(guide = F) + + xlab('Date') + ylab('Vote Share') + + scale_y_continuous(breaks = seq(0,1,by = .25),limits = c(0,1.25)) + + theme(legend.position = 'bottom') + + +p2 <- toplot %>% + ggplot(aes(x = log(casesSum+1),y = voteSh,color = factor(extreme))) + + geom_jitter(alpha = .2,width = .2) + + geom_smooth(method = 'lm') + + theme_ridges() + + scale_color_manual(name = 'Type',values = c(`0` = 'grey60',`1` = 'black'),label = c('Mainstream','Extreme')) + + scale_alpha_manual(guide = F,values = c(`0` = .15,`1` = .6)) + + scale_size_continuous(guide = F) + + xlab('Logged Cases') + ylab('Vote Share') + + scale_y_continuous(breaks = seq(0,1,by = .25),limits = c(0,1.25)) + + theme(legend.position = 'bottom') + +pdf('../Figures/SI_figure18.pdf',width = 12,height = 8) +grid.arrange(p1,p2,ncol = 2) +dev.off() diff --git a/29/replication_package/Code/helper_functions.R b/29/replication_package/Code/helper_functions.R new file mode 100644 index 0000000000000000000000000000000000000000..e647b2cc1deba1fef0da8d281aad1f459a2d68d9 --- /dev/null +++ b/29/replication_package/Code/helper_functions.R @@ -0,0 +1,206 @@ +# QQ plot to evaluate balance +qqprep <- function (x, discrete.cutoff, which.subclass = NULL, numdraws = 5000, + interactive = T, which.xs = NULL, ...) { + X <- x$X + varnames <- colnames(X) + for (var in varnames) { + if (is.factor(X[, var])) { + tempX <- X[, !colnames(X) %in% c(var)] + form <- formula(substitute(~dummy - 1, list(dummy = as.name(var)))) + X <- cbind(tempX, model.matrix(form, X)) + } + } + covariates <- X + if (!is.null(which.xs)) { + if (sum(which.xs %in% dimnames(covariates)[[2]]) != length(which.xs)) { + stop("which.xs is incorrectly specified") + } + covariates <- covariates[, which.xs, drop = F] + } + treat <- x$treat + matched <- x$weights != 0 + ratio <- x$call$ratio + if (is.null(ratio)) { + ratio <- 1 + } + if (identical(x$call$method, "full") | (ratio != 1)) { + t.plot <- sample(names(treat)[treat == 1], numdraws/2, + replace = TRUE, prob = x$weights[treat == 1]) + c.plot <- sample(names(treat)[treat == 0], numdraws/2, + replace = TRUE, prob = x$weights[treat == 0]) + m.covariates <- x$X[c(t.plot, c.plot), ] + m.treat <- x$treat[c(t.plot, c.plot)] + } + else { + m.covariates <- covariates[matched, , drop = F] + m.treat <- treat[matched] + } + if (!is.null(which.subclass)) { + subclass <- x$subclass + sub.index <- subclass == which.subclass & !is.na(subclass) + sub.covariates <- covariates[sub.index, , drop = F] + sub.treat <- treat[sub.index] + sub.matched <- matched[sub.index] + m.covariates <- sub.covariates[sub.matched, , drop = F] + m.treat <- sub.treat[sub.matched] + } + nn <- dimnames(covariates)[[2]] + nc <- length(nn) + covariates <- data.matrix(covariates) + toplot <- NULL + for (i in 1:nc) { + xi <- covariates[, i] + m.xi <- m.covariates[, i] + rr <- range(xi) + + + eqqplot <- function(x,y) { + sx <- sort(x) + sy <- sort(y) + lenx <- length(sx) + leny <- length(sy) + if (leny < lenx) + sx <- approx(1:lenx, sx, n = leny, method = "constant")$y + if (leny > lenx) + sy <- approx(1:leny, sy, n = lenx, method = "constant")$y + return(list(x = sx,y = sy)) + } + toplot <- bind_rows(toplot, + bind_rows(data.frame(eqqplot(x = xi[treat == 0],y = xi[treat == 1]),type = "Raw",cov = nn[i],rrlb = rr[1],rrub = rr[2]), + data.frame(eqqplot(x = m.xi[m.treat == 0],y = m.xi[m.treat == 1]),type = "Matched",cov = nn[i],rrlb = rr[1],rrub = rr[2]))) + } + return(list(toplot = toplot)) +} + + +# Ineration plot +interaction_plot_continuous <- function(model, effect = "", moderator = "", varcov="default", minimum="min", maximum="max",colr = "grey", + incr="default", num_points = 10, conf=.95, mean=FALSE, median=FALSE, alph=80, rugplot=T, + histogram=F, title="Marginal effects plot", xlabel="Value of moderator", + ylabel="Estimated marginal coefficient",pointsplot = F,plot = F,show_est = F) { + # Extract Variance Covariance matrix + if (varcov == "default"){ + covMat = vcov(model) + }else{ + covMat = varcov + } + + # Extract the data frame of the model + mod_frame = model.frame(model) + + # Get coefficients of variables + if(effect == "") { + int.string <- rownames(summary(model)$coefficients)[grepl(":",rownames(summary(model)$coefficients))] + effect <- substr(int.string,1,regexpr(":",int.string)[1]-1) + } + if(moderator == "") { + int.string <- rownames(summary(model)$coefficients)[grepl(":",rownames(summary(model)$coefficients))] + moderator <- substr(int.string,regexpr(":",int.string)[1]+1,nchar(int.string)) + } + interaction <- paste(effect,":",moderator,sep="") + beta_1 = summary(model)$coefficients[effect,1] + beta_3 = summary(model)$coefficients[interaction,1] + + # Set range of the moderator variable + # Minimum + if (minimum == "min"){ + min_val = min(mod_frame[[moderator]]) + }else{ + min_val = minimum + } + # Maximum + if (maximum == "max"){ + max_val = max(mod_frame[[moderator]]) + }else{ + max_val = maximum + } + + # Check if minimum smaller than maximum + if (min_val > max_val){ + stop("Error: Minimum moderator value greater than maximum value.") + } + + # Determine intervals between values of the moderator + if (incr == "default"){ + increment = (max_val - min_val)/(num_points - 1) + }else{ + increment = incr + } + + # Create list of moderator values at which marginal effect is evaluated + x_2 <- seq(from=min_val, to=max_val, by=increment) + + # Compute marginal effects + delta_1 = beta_1 + beta_3*x_2 + + # Compute variances + var_1 = covMat[effect,effect] + (x_2^2)*covMat[interaction, interaction] + 2*x_2*covMat[effect, interaction] + + # Standard errors + se_1 = sqrt(var_1) + + # Upper and lower confidence bounds + z_score = qnorm(1 - ((1 - conf)/2)) + upper_bound = sapply(1:length(z_score), function(x) delta_1 + z_score[x]*se_1) + lower_bound = sapply(1:length(z_score), function(x) delta_1 - z_score[x]*se_1) + + # Determine the bounds of the graphing area + max_y = max(upper_bound) + min_y = min(lower_bound) + + # Make the histogram color + hist_col = colr + + stars <- ifelse(abs(summary(model)$coefficients[interaction,3]) >2.6,"***", + ifelse(abs(summary(model)$coefficients[interaction,3]) > 1.96,"**", + ifelse(abs(summary(model)$coefficients[interaction,3]) > 1.65,"*",""))) + est <- paste("Interaction: ",round(summary(model)$coefficients[interaction,1],3),stars," (", + round(summary(model)$coefficients[interaction,2],3),")",sep="") + # Initialize plotting window + if(plot) { + plot(x=c(), y=c(), ylim=c(min_y, max_y), xlim=c(min_val, max_val), + xlab=xlabel, ylab=ylabel, main=title) + + # Plot estimated effects + if(!pointsplot) { + lines(y=delta_1, x=x_2,col = colr) + for(i in ncol(upper_bound):1) { + polygon(c(x_2,rev(x_2)),c(upper_bound[,i],rev(lower_bound[,i])),border = NA,col = colr) + } + }else{ + points(y = delta_1,x = x_2,col = colr,pch = 19) + for(i in ncol(upper_bound):1) { + segments(x_2,upper_bound[,i],x_2,lower_bound[,i],col = colr,lwd = i) + } + } + # Add a dashed horizontal line for zero + abline(h=0, lty=3) + + # Add a vertical line at the mean + if (mean){ + abline(v = mean(mod_frame[[moderator]]), lty=2, col="red") + } + + # Add a vertical line at the median + if (median){ + abline(v = median(mod_frame[[moderator]]), lty=3, col="blue") + } + + # Add Rug plot + if (rugplot){ + rug(mod_frame[[moderator]]) + } + + if (show_est) { + text(par('usr')[ 2 ], par('usr')[ 4 ],adj=c(1.05,1.2), + labels = est) + + } + #Add Histogram (Histogram only plots when minimum and maximum are the min/max of the moderator) + if (histogram & minimum=="min" & maximum=="max"){ + par(new=T) + hist(mod_frame[[moderator]], axes=F, xlab="", ylab="",main="", border=hist_col, col=hist_col) + } + } + return(list(delta_1 = delta_1,x_2 = x_2,ub = upper_bound,lb = lower_bound,inc = increment,est = est)) +} diff --git a/29/replication_package/Code/zzSI_robust_prep.R b/29/replication_package/Code/zzSI_robust_prep.R new file mode 100644 index 0000000000000000000000000000000000000000..048a5582efe6bd8e91277399022fac28a983de7d --- /dev/null +++ b/29/replication_package/Code/zzSI_robust_prep.R @@ -0,0 +1,161 @@ +# File name: SI_robust_prep.R +# In: +# - replication_data.RData +# Out: +# - /Data/Results/SI-data.RData + +require(lme4) +require(lfe) +require(MatchIt) +require(WeightIt) +require(tjbal) +require(optmatch) +require(stargazer) +require(cobalt) +require(gridExtra) +require(ggridges) +require(ggrepel) +require(CBPS) +require(tidyverse) +rm(list = ls()) +gc() + +####################################################################################################################### Loading data +load('../Data/replication_data.RData') + + + + +####################################################################################################################### Loading functions +source('./helper_functions.R') + + + +# ####################################################################################################################### Command line arguments +# args <- commandArgs(trailingOnly = T) +# # args <- c(3,2,2,2) +# # Y: 1-3 +# # D: 1-2 +# # FE: 1-4 +# # GEO: 1-2 +# yInd <- as.numeric(args[1]) +# dInd <- as.numeric(args[2]) +# feInd <- as.numeric(args[3]) +# geoInd <- as.numeric(args[4]) + + + +####################################################################################################################### Preparing variables +Y <- paste0(c("pct_","VAP_","pcttw_"),"sanders") +D <- unlist(lapply(c("sc_","ln_"),function(x) paste0(x,paste0(c("county_","DMA_","state_"),"cases")))) +FE <- c("0","DMA_CODE","date") +covariates <- c("sc_CTY_LTHS","sc_CTY_CollUp", + "sc_CTY_LT30yo","sc_CTY_60Up", + "sc_CTY_Below_poverty_level_AGE_18_64","sc_CTY_Female_hher_no_husbandhh", + "sc_CTY_Unem_rate_pop_16_over","sc_CTY_Labor_Force_Part_Rate_pop_16_over", + "sc_CTY_Manufactur","sc_CTY_Md_inc_hhs", + "sc_CTY_POPPCT_RURAL","sc_CTY_Speak_only_English","sc_CTY_White","sc_CTY_Black_or_African_American", + "ln_CTY_tot_pop","sc_turnout_pct_20") + + +set.seed(123) +resSI <- list() +for(y in 'pcttw_sanders') { + for(fe in c('DMA_CODE','0')) { + for(geo in 'DMA_') { + for(d in c('March10Cases','March17Cases')) { + for(pre in c("2020-03-01","2020-03-03","2020-03-10","2020-03-17")) { + for(post in c("2020-03-01","2020-03-03","2020-03-10","2020-03-17")) { + if(pre == post) { next } + + if(pre == "2020-03-01") { + finalDat$post <- ifelse(finalDat$date == as.Date(post),1, + ifelse(finalDat$date <= as.Date(pre),0,NA)) + } else if(post == "2020-03-01") { + finalDat$post <- ifelse(finalDat$date <= as.Date(post),1, + ifelse(finalDat$date == as.Date(pre),0,NA)) + } else { + finalDat$post <- ifelse(finalDat$date == as.Date(post),1, + ifelse(finalDat$date == as.Date(pre),0,NA)) + } + finalDat$treatBin <- ifelse(finalDat[[paste0(geo,d)]] > 1,1,0) + finalDat$treat <- ifelse(finalDat$post == 1 & finalDat$treatBin == 1,1,0) + tmpAnal <- finalDat %>% select(Y,treat,treatBin,c(covariates,paste0(y,"16")),pcttw_sanders16,VAP_sanders16,DMA_CODE,date,stab,matches("cases"),post) %>% filter(complete.cases(.)) + m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), + data = tmpAnal, + method = "nearest", + distance = "mahalanobis") + + m.data <- match.data(m.out) + W.out <- weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), + data = tmpAnal, estimand = "ATT", method = "cbps") + + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) + + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) + + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$bin <- summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$cont <- summary(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$did$coefs <- summary(tmp <- felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$did$mfx <- interaction_plot_continuous(tmp,num_points = 2,pointsplot = T) + + # Permutation SHEEYAHT + basic.bin.plac <- basic.cont.plac <- basic.did.plac <- matching.bin.plac <- matching.cont.plac <- matching.did.plac <- weighting.bin.plac <- weighting.cont.plac <- weighting.did.plac <- NULL + for(bs in 1:100) { + tmpAnal$perm <- sample(tmpAnal[[paste0(geo,d)]],size = nrow(tmpAnal)) + tmpAnal$treatBin <- ifelse(tmpAnal$perm > 1,1,0) + tmpAnal$treat <- ifelse(tmpAnal$post == 1 & tmpAnal$treatBin == 1,1,0) + m.out <- matchit(formula = as.formula(paste("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), + data = tmpAnal, + method = "full", + distance = "mahalanobis") + + m.data <- match.data(m.out) + W.out <- weightit(formula(paste0("treatBin ~ ",paste(c(covariates,paste0(y,"16")),collapse = " + "))), + data = tmpAnal, estimand = "ATT", method = "cbps") + + test <- tryCatch(felm(as.formula(paste0('scale(',y,") ~ ",paste0("scale(",geo,d,")")," + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights),error = function(e) e) + if(inherits(test,"error")) { next } + basic.bin.plac <- c(basic.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients['treat',1]) + basic.cont.plac <- c(basic.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients["scale(perm)",1]) + basic.did.plac <- c(basic.did.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal))$coefficients["treatBin:post",1]) + + matching.bin.plac <- c(matching.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients['treat',1]) + matching.cont.plac <- c(matching.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients["scale(perm)",1]) + matching.did.plac <- c(matching.did.plac, + summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),m.data,weights = m.data$weights))$coefficients["treatBin:post",1]) + + weighting.bin.plac <- c(weighting.bin.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treat + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients['treat',1]) + weighting.cont.plac <- c(weighting.cont.plac,summary(felm(as.formula(paste0('scale(',y,") ~ scale(perm) + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients["scale(perm)",1]) + weighting.did.plac <- c(weighting.did.plac,summary(felm(as.formula(paste0('scale(',y,") ~ treatBin*post + ",paste(c(covariates,paste0(y,"16")),collapse = "+"),"| 0 | 0 | ",fe)),tmpAnal,weights = W.out$weights))$coefficients["treatBin:post",1]) + + cat(".") + } + cat('\n') + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$bin <- basic.bin.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$cont <- basic.cont.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$basic$plac$did <- basic.did.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$bin <- matching.bin.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$cont <- matching.cont.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$matching$plac$did <- matching.did.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$bin <- weighting.bin.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$cont <- weighting.cont.plac + resSI[[y]][[geo]][[d]][[fe]][[pre]][[post]]$felm$weighting$plac$did <- weighting.did.plac + } + } + } + } + } + cat(y," done\n") +} + + +save(resSI,file = paste0("../Data/Results/SI-data.RData")) + + diff --git a/29/replication_package/Data/Pew/biden_sanders_ideo_feb_march_PEW.csv b/29/replication_package/Data/Pew/biden_sanders_ideo_feb_march_PEW.csv new file mode 100644 index 0000000000000000000000000000000000000000..b58c279ddbe910ff778fc6bd800f3652996f674a --- /dev/null +++ b/29/replication_package/Data/Pew/biden_sanders_ideo_feb_march_PEW.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:159d10048cec7aa71a84121e6cef5bc270bbfd91af5da4f82cbd7a4288479289 +size 758 diff --git a/29/replication_package/Data/Results/SI-data.RData b/29/replication_package/Data/Results/SI-data.RData new file mode 100644 index 0000000000000000000000000000000000000000..774bf206efb14400b665ba01eb76e21091ae34c6 --- /dev/null +++ b/29/replication_package/Data/Results/SI-data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ab476e6942ab301cc9c95915213a0f0c1503878dc5cd1139c0dbe96579a0d2d2 +size 612519 diff --git a/29/replication_package/Data/Results/tjbalWgtsNEW.RData b/29/replication_package/Data/Results/tjbalWgtsNEW.RData new file mode 100644 index 0000000000000000000000000000000000000000..cc0771dc9935982ebb7a1e57a7578c27f46fcc91 --- /dev/null +++ b/29/replication_package/Data/Results/tjbalWgtsNEW.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08ae796fec1e3fc0255d86b57fe7aa2cd06d6395ea53a5f7f1757f4467e4008d +size 694122 diff --git a/29/replication_package/Data/france_data.RData b/29/replication_package/Data/france_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..be6aab04dac795cf80814652ec8ff943da73ef0a --- /dev/null +++ b/29/replication_package/Data/france_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a6f0c86de924e700ca3bf8758cf1bd89256c7b7820ae0a52b2243a900fcb9d1b +size 4168 diff --git a/29/replication_package/Data/gtrends_data.RData b/29/replication_package/Data/gtrends_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..e334378a0b674edb210e8096e74c962979eb13f8 --- /dev/null +++ b/29/replication_package/Data/gtrends_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:27e035cbf2594a8efdc2b95f2e3171d435ed835cd498c8577d785c5a3c83e4d1 +size 197370 diff --git a/29/replication_package/Data/mobility_data.RData b/29/replication_package/Data/mobility_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..434e651e1a2493803f15c4206902b10e3724c119 --- /dev/null +++ b/29/replication_package/Data/mobility_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae2ed4bc824bd34c0af6e2093730363c61fff688686ece88ba953d6825433e30 +size 469100 diff --git a/29/replication_package/Data/nationscape_data.RData b/29/replication_package/Data/nationscape_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..869d4e58dca05478343137e3f5bddbee5dfcddd7 --- /dev/null +++ b/29/replication_package/Data/nationscape_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:788e8ad26b105cd3aa19e0960a47fc44a0d37c32292d7c4a205ea3a075ea9cd6 +size 27497508 diff --git a/29/replication_package/Data/primary_data.RData b/29/replication_package/Data/primary_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..a43f002843e8cb4fb4983b623751a6250b5fbf2b --- /dev/null +++ b/29/replication_package/Data/primary_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2cc73e721d0b93cb122a077fbf0711c0388668d1a6bf66ea468f96423ca87b49 +size 60772 diff --git a/29/replication_package/Data/replication_data.RData b/29/replication_package/Data/replication_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..8ce4a27af81dc1c64a282085dc1b9cfcc4834bd4 --- /dev/null +++ b/29/replication_package/Data/replication_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f9e444e6793f7dd569fc17e9ca8b42df53960580c8144456648ca3379d1ed82f +size 9279609 diff --git a/29/replication_package/Data/survey_experiment_data.RData b/29/replication_package/Data/survey_experiment_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..bc087c0883e7e73f9806ae5eb05fefc1d399e4cc --- /dev/null +++ b/29/replication_package/Data/survey_experiment_data.RData @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edab07dfde669772bac532ec9b86741db8ff6f367a0c56397928d8bb10a09de1 +size 23389 diff --git a/29/replication_package/Figures/SI_figure1.pdf b/29/replication_package/Figures/SI_figure1.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1523a9da8a593af3a6ab401d3d2f250a07d19126 --- /dev/null +++ b/29/replication_package/Figures/SI_figure1.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7192c65016253a89ff73933b49c0848a63e427512d6bebf07b5dbb91699c0b95 +size 6336 diff --git a/29/replication_package/Figures/SI_figure10.pdf b/29/replication_package/Figures/SI_figure10.pdf new file mode 100644 index 0000000000000000000000000000000000000000..838ab8b4d396dd527f87a638451431c6b02b9ab0 --- /dev/null +++ b/29/replication_package/Figures/SI_figure10.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7c1ab6e919d917bc6b968e548f16759b1ed3e0823172a7afc22df391ede2745d +size 5579 diff --git a/29/replication_package/Figures/SI_figure11.pdf b/29/replication_package/Figures/SI_figure11.pdf new file mode 100644 index 0000000000000000000000000000000000000000..335d62e800d0fc8066a23b4ce554c78aae39f2dc --- /dev/null +++ b/29/replication_package/Figures/SI_figure11.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d04e684de9173271a239189e07d683b05227fbf95e64243b1a465f021f8b8fa +size 62125 diff --git a/29/replication_package/Figures/SI_figure12.pdf b/29/replication_package/Figures/SI_figure12.pdf new file mode 100644 index 0000000000000000000000000000000000000000..7dcedc63643c3bf53a6504da1456837ab34d14d5 --- /dev/null +++ b/29/replication_package/Figures/SI_figure12.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6b1ab107ee1d2fae07f5b450291aefd3749efb07f0a8a9778dbb37c94b7dbe63 +size 4449 diff --git a/29/replication_package/Figures/SI_figure13.pdf b/29/replication_package/Figures/SI_figure13.pdf new file mode 100644 index 0000000000000000000000000000000000000000..7eb4103468aaa7e549569ed6c5dae204777989ab --- /dev/null +++ b/29/replication_package/Figures/SI_figure13.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7bb03b2674f7465f06b2a3eef9c65d101817e2367b14fe963b564bab9fef56ff +size 515152 diff --git a/29/replication_package/Figures/SI_figure14.pdf b/29/replication_package/Figures/SI_figure14.pdf new file mode 100644 index 0000000000000000000000000000000000000000..395934944b291f3181b86a2b9ed29632c2c0e769 --- /dev/null +++ b/29/replication_package/Figures/SI_figure14.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c3b82229f49e0e1d322910ada6ddc2731f280a100a0b648037f4fc6340cf83c +size 134261 diff --git a/29/replication_package/Figures/SI_figure15.pdf b/29/replication_package/Figures/SI_figure15.pdf new file mode 100644 index 0000000000000000000000000000000000000000..be348a6c9e9e309b2631899ce647a7537ec7972e --- /dev/null +++ b/29/replication_package/Figures/SI_figure15.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40dedefec9dc40ccb32f4dcb04b2ffd8f6b796e0c6a98e615461f4d4bc7c6f4f +size 64107 diff --git a/29/replication_package/Figures/SI_figure16.pdf b/29/replication_package/Figures/SI_figure16.pdf new file mode 100644 index 0000000000000000000000000000000000000000..3fa9cf9eb6e7ff9e6e8824719754845012e58c21 --- /dev/null +++ b/29/replication_package/Figures/SI_figure16.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbd3b1a7a87b2224dcb0ada95c68aec54129a0b64c79d11d804f52e211c0a106 +size 176520 diff --git a/29/replication_package/Figures/SI_figure17.pdf b/29/replication_package/Figures/SI_figure17.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d35978d0ba5acb229041e6515d5782a551165635 --- /dev/null +++ b/29/replication_package/Figures/SI_figure17.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfd85007fd61ae94a998ff23d0046a0f2d84da9bb520e7101e226dd71b4c2c55 +size 4881 diff --git a/29/replication_package/Figures/SI_figure18.pdf b/29/replication_package/Figures/SI_figure18.pdf new file mode 100644 index 0000000000000000000000000000000000000000..b2f5b52d9b798e97c24c55fa070213201816576a --- /dev/null +++ b/29/replication_package/Figures/SI_figure18.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91f210e639e55de4ea6eb28b3d210ee1f0d214a24a1cc31147b9c28baff26c2e +size 184291 diff --git a/29/replication_package/Figures/SI_figure19.pdf b/29/replication_package/Figures/SI_figure19.pdf new file mode 100644 index 0000000000000000000000000000000000000000..667b91b945a6f16a7cb499aae3c293da1d7c05f9 --- /dev/null +++ b/29/replication_package/Figures/SI_figure19.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1f0826ab4ebf5b3196d8c4591ee5f6b6c956a5e10ba6692cfe32c950a7a1e8b2 +size 6784 diff --git a/29/replication_package/Figures/SI_figure2.pdf b/29/replication_package/Figures/SI_figure2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c86eb2c422647872822bb9068c0145029b83babe --- /dev/null +++ b/29/replication_package/Figures/SI_figure2.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fa6540bf7aaf4b7fc03e572e6b91927d2d0718d77af88c85a24821c9dedfb82c +size 5832 diff --git a/29/replication_package/Figures/SI_figure3.pdf b/29/replication_package/Figures/SI_figure3.pdf new file mode 100644 index 0000000000000000000000000000000000000000..da5e97ee54de42a32a61d1dec7562e11d884efe5 --- /dev/null +++ b/29/replication_package/Figures/SI_figure3.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a5da83037731b1a69c5ee46c613ca572ef48b4199673989f41a3718c84a81e3 +size 43801 diff --git a/29/replication_package/Figures/SI_figure4.pdf b/29/replication_package/Figures/SI_figure4.pdf new file mode 100644 index 0000000000000000000000000000000000000000..2882ce32558851c65daed8fc0ffff33084e5e677 --- /dev/null +++ b/29/replication_package/Figures/SI_figure4.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e90f05534621786f73869f7cb0a6c6eb8fa30865521d8dc63ca49737b9ba80d7 +size 7792 diff --git a/29/replication_package/Figures/SI_figure5.pdf b/29/replication_package/Figures/SI_figure5.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e7071d820ae456c06d97574b8f57edce256f9a95 --- /dev/null +++ b/29/replication_package/Figures/SI_figure5.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dd63ce9534f2bd579f8857fccf7f1ae3d4a752cc00a62ee730beecc685400939 +size 6759 diff --git a/29/replication_package/Figures/SI_figure6.pdf b/29/replication_package/Figures/SI_figure6.pdf new file mode 100644 index 0000000000000000000000000000000000000000..02ffb50971d1f42f0e8d611717f3455881bb6465 --- /dev/null +++ b/29/replication_package/Figures/SI_figure6.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a49f525250d92dfc3db49241db7e49e1c3e5978b4ed03908700a14245e1a07d6 +size 6816 diff --git a/29/replication_package/Figures/SI_figure7.pdf b/29/replication_package/Figures/SI_figure7.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c51ce2c1508ad96ebe692c8a9d8e58e3ec19690c --- /dev/null +++ b/29/replication_package/Figures/SI_figure7.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4aa7817d515f572e15ba8cad5bd8f0ffaf854caca3107d7c369519a9411d137b +size 7096 diff --git a/29/replication_package/Figures/SI_figure8.pdf b/29/replication_package/Figures/SI_figure8.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1b803eb1bc850c3c6f531d23099fc82e12f80ae8 --- /dev/null +++ b/29/replication_package/Figures/SI_figure8.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:513bf9759f436e0d825f0964af24ec2b7a99dbe7aa8b53220d4b3170bbcb8311 +size 110874 diff --git a/29/replication_package/Figures/SI_figure9.pdf b/29/replication_package/Figures/SI_figure9.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e2ab9a5538f16c51d3f76f2acbbc921f27ea303f --- /dev/null +++ b/29/replication_package/Figures/SI_figure9.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e99fccd987a5a299d35850e3ced3cdc76d2602577559de1293f037cc583ad9f0 +size 5834 diff --git a/29/replication_package/Figures/figure2.pdf b/29/replication_package/Figures/figure2.pdf new file mode 100644 index 0000000000000000000000000000000000000000..30c6338b158ed4be6bd4dff14d6bddd32aa33498 --- /dev/null +++ b/29/replication_package/Figures/figure2.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95b86f2ee3315f6e39ec526d11eeb25923abc6966c6d83ff137754f0f3d6e84d +size 1562305 diff --git a/29/replication_package/Figures/figure2.png b/29/replication_package/Figures/figure2.png new file mode 100644 index 0000000000000000000000000000000000000000..fd6a4d3ac6f9b4f2af5ed28aa6d70f83b988d1dd --- /dev/null +++ b/29/replication_package/Figures/figure2.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b36cc2ae074facc2c82b431855236cbd23641a22d20d1ef33b9cdcdfc4e34f3 +size 785837 diff --git a/29/replication_package/Figures/figure3.pdf b/29/replication_package/Figures/figure3.pdf new file mode 100644 index 0000000000000000000000000000000000000000..319cd7fe00684a267896cac135f05eb55b5f08d7 --- /dev/null +++ b/29/replication_package/Figures/figure3.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7567ad9719fd5aae792931c0cd4b7d68a14588a696a1fedbdd47e006f8ec0388 +size 108282 diff --git a/29/replication_package/Figures/figure4.pdf b/29/replication_package/Figures/figure4.pdf new file mode 100644 index 0000000000000000000000000000000000000000..0b605f9ce26d56004c8aafa1b8f63b8b6ff0e199 --- /dev/null +++ b/29/replication_package/Figures/figure4.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15bb0e4d37343d6b54c6c4d74f9980cc026fa18698181288c0e19e78b45e73ec +size 4411 diff --git a/29/replication_package/Figures/figure5.pdf b/29/replication_package/Figures/figure5.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c7a358a53886a7161af3a573d214c95ce149e401 --- /dev/null +++ b/29/replication_package/Figures/figure5.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e715d04275bb3861af419ea80adb0f6cf1a655c08c7bc289a9efdec687ecbe28 +size 5788 diff --git a/29/replication_package/Figures/figure6.pdf b/29/replication_package/Figures/figure6.pdf new file mode 100644 index 0000000000000000000000000000000000000000..c0105a8de5cba637d1b5e8dc494c6a7be2082563 --- /dev/null +++ b/29/replication_package/Figures/figure6.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d7bab84707dc53100885cb3d089e0d4f1de84ddda3554b76fbd783e28dbad26 +size 16111 diff --git a/29/replication_package/Figures/figure7.pdf b/29/replication_package/Figures/figure7.pdf new file mode 100644 index 0000000000000000000000000000000000000000..5737f242f8b0fb3a44954191f43dcb1382fe576a --- /dev/null +++ b/29/replication_package/Figures/figure7.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:392ac03d0a37bb61e9f2243bee409c461d9b8c5de3db644002cbdc0f6f9a23f0 +size 13762 diff --git a/29/replication_package/Figures/figure8.pdf b/29/replication_package/Figures/figure8.pdf new file mode 100644 index 0000000000000000000000000000000000000000..9667d41a9597dea672dda003e04fabfafd174612 --- /dev/null +++ b/29/replication_package/Figures/figure8.pdf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c4d0a23c3433575ef6a3ac80927f9860577992a94155d240d947dc466a4fec5 +size 26674 diff --git a/29/replication_package/Tables/SI-table1.tex b/29/replication_package/Tables/SI-table1.tex new file mode 100644 index 0000000000000000000000000000000000000000..287a92a36f9861c4ac12fb53fa4a589a2d87d90f --- /dev/null +++ b/29/replication_package/Tables/SI-table1.tex @@ -0,0 +1,33 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Wed, Jun 16, 2021 - 11:44:44 PM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}} cccccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & variable & avg\_0 & avg\_1 & p\_value & t\_value \\ +\hline \\[-1.8ex] +1 & pct sanders16 & $39.7$ & $46.1$ & $0$ & $$-$8.9$ \\ +2 & caucus switch & $0.1$ & $0.2$ & $0$ & $$-$8.6$ \\ +3 & Speak only English & $86.8$ & $92$ & $0$ & $$-$8.5$ \\ +4 & Manufactur & $11.7$ & $13.5$ & $0$ & $$-$6$ \\ +5 & Labor Force Part Rate pop 16 over & $56.9$ & $59$ & $0$ & $$-$5.8$ \\ +6 & caucus & $0$ & $0.1$ & $0$ & $$-$5.3$ \\ +7 & White & $81.1$ & $84.7$ & $0$ & $$-$5$ \\ +8 & POPPCT RURAL & $54.4$ & $60.3$ & $0$ & $$-$4.2$ \\ +9 & CollUp & $29$ & $30.2$ & $0.01$ & $$-$2.6$ \\ +10 & Md inc hhs & $49,328.1$ & $49,575.1$ & $0.7$ & $$-$0.4$ \\ +11 & 60Up & $24.8$ & $24.8$ & $1.0$ & $0$ \\ +12 & LT30yo & $37.4$ & $37$ & $0.1$ & $1.4$ \\ +13 & Below poverty level AGE 18 64 & $9.4$ & $8.9$ & $0$ & $2.9$ \\ +14 & turnout pct 20 & $9.1$ & $8.2$ & $0$ & $3.1$ \\ +15 & Black or African American & $11$ & $8.3$ & $0$ & $3.9$ \\ +16 & tot pop & $167,608$ & $76,765.9$ & $0$ & $4.5$ \\ +17 & LTHS & $15$ & $13.5$ & $0$ & $5$ \\ +18 & Unem rate pop 16 over & $6.9$ & $6.2$ & $0$ & $5.6$ \\ +19 & Female hher no husbandhh & $11.9$ & $10.8$ & $0$ & $6$ \\ +\hline \\[-1.8ex] +\end{tabular} +\end{table} diff --git a/29/replication_package/Tables/SI-table3.tex b/29/replication_package/Tables/SI-table3.tex new file mode 100644 index 0000000000000000000000000000000000000000..7394253337fa77550f723a534d578999145a8ad8 --- /dev/null +++ b/29/replication_package/Tables/SI-table3.tex @@ -0,0 +1,32 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Thu, Jun 17, 2021 - 12:52:24 AM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}} cccccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & Covs & Diff\_Unm & Bal\_Test\_Unm & Diff\_Match & Bal\_Test\_Match \\ +\hline \\[-1.8ex] +1 & prop.score & $$ & & $0.150$ & \\ +2 & sc\_CTY\_LTHS & $$-$0.600$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +3 & sc\_CTY\_CollUp & $0.590$ & Not Balanced, \textgreater 0.05 & $0.040$ & Balanced, \textless 0.05 \\ +4 & sc\_CTY\_LT30yo & $$-$0.190$ & Not Balanced, \textgreater 0.05 & $$-$0.060$ & Not Balanced, \textgreater 0.05 \\ +5 & sc\_CTY\_60Up & $0.160$ & Not Balanced, \textgreater 0.05 & $0.070$ & Not Balanced, \textgreater 0.05 \\ +6 & sc\_CTY\_Below\_poverty\_level\_AGE\_18\_64 & $$-$0.570$ & Not Balanced, \textgreater 0.05 & $$-$0.020$ & Balanced, \textless 0.05 \\ +7 & sc\_CTY\_Female\_hher\_no\_husbandhh & $$-$0.510$ & Not Balanced, \textgreater 0.05 & $$-$0.010$ & Balanced, \textless 0.05 \\ +8 & sc\_CTY\_Unem\_rate\_pop\_16\_over & $$-$0.240$ & Not Balanced, \textgreater 0.05 & $0.010$ & Balanced, \textless 0.05 \\ +9 & sc\_CTY\_Labor\_Force\_Part\_Rate\_pop\_16\_over & $0.360$ & Not Balanced, \textgreater 0.05 & $$-$0.050$ & Balanced, \textless 0.05 \\ +10 & sc\_CTY\_Manufactur & $$-$0.210$ & Not Balanced, \textgreater 0.05 & $$-$0.040$ & Balanced, \textless 0.05 \\ +11 & sc\_CTY\_Md\_inc\_hhs & $0.620$ & Not Balanced, \textgreater 0.05 & $0.040$ & Balanced, \textless 0.05 \\ +12 & sc\_CTY\_POPPCT\_RURAL & $$-$0.560$ & Not Balanced, \textgreater 0.05 & $$-$0.050$ & Balanced, \textless 0.05 \\ +13 & sc\_CTY\_Speak\_only\_English & $$-$0.310$ & Not Balanced, \textgreater 0.05 & $$-$0.050$ & Not Balanced, \textgreater 0.05 \\ +14 & sc\_CTY\_White & $0.330$ & Not Balanced, \textgreater 0.05 & $$-$0.050$ & Balanced, \textless 0.05 \\ +15 & sc\_CTY\_Black\_or\_African\_American & $$-$1.170$ & Not Balanced, \textgreater 0.05 & $0.020$ & Balanced, \textless 0.05 \\ +16 & ln\_CTY\_tot\_pop & $0.510$ & Not Balanced, \textgreater 0.05 & $0.050$ & Not Balanced, \textgreater 0.05 \\ +17 & sc\_turnout\_pct\_20 & $0.420$ & Not Balanced, \textgreater 0.05 & $0.030$ & Balanced, \textless 0.05 \\ +18 & caucus\_switch & $0.060$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +\hline \\[-1.8ex] +\end{tabular} +\end{table} diff --git a/29/replication_package/Tables/SI-table4.tex b/29/replication_package/Tables/SI-table4.tex new file mode 100644 index 0000000000000000000000000000000000000000..5533f44fe97328eeb77ec2d2216f3a389910e19f --- /dev/null +++ b/29/replication_package/Tables/SI-table4.tex @@ -0,0 +1,31 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Thu, Jun 17, 2021 - 12:52:28 AM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}} cccccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & Covs & Diff\_Unm & Bal\_Test\_Unm & Diff\_Match & Bal\_Test\_Match \\ +\hline \\[-1.8ex] +1 & sc\_CTY\_LTHS & $$-$0.530$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +2 & sc\_CTY\_CollUp & $0.540$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +3 & sc\_CTY\_LT30yo & $$-$0.170$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +4 & sc\_CTY\_60Up & $0.140$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +5 & sc\_CTY\_Below\_poverty\_level\_AGE\_18\_64 & $$-$0.490$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +6 & sc\_CTY\_Female\_hher\_no\_husbandhh & $$-$0.460$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +7 & sc\_CTY\_Unem\_rate\_pop\_16\_over & $$-$0.180$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +8 & sc\_CTY\_Labor\_Force\_Part\_Rate\_pop\_16\_over & $0.290$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +9 & sc\_CTY\_Manufactur & $$-$0.260$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +10 & sc\_CTY\_Md\_inc\_hhs & $0.590$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +11 & sc\_CTY\_POPPCT\_RURAL & $$-$0.550$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +12 & sc\_CTY\_Speak\_only\_English & $$-$0.330$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +13 & sc\_CTY\_White & $0.300$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +14 & sc\_CTY\_Black\_or\_African\_American & $$-$1.160$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +15 & ln\_CTY\_tot\_pop & $0.520$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +16 & sc\_turnout\_pct\_20 & $0.450$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +17 & caucus\_switch & $0.070$ & Not Balanced, \textgreater 0.05 & $0$ & Balanced, \textless 0.05 \\ +\hline \\[-1.8ex] +\end{tabular} +\end{table} diff --git a/29/replication_package/Tables/SI-table5.tex b/29/replication_package/Tables/SI-table5.tex new file mode 100644 index 0000000000000000000000000000000000000000..827d4adc921e751774e6927812a6a55184f7f7ab --- /dev/null +++ b/29/replication_package/Tables/SI-table5.tex @@ -0,0 +1,79 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Thu, Jun 17, 2021 - 12:52:28 AM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}}lcccccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & \multicolumn{6}{c}{\textit{Dependent variable:}} \\ +\cline{2-7} +\\[-1.8ex] & \multicolumn{3}{c}{paste0("scale(pcttw\_sanders) \textasciitilde treatBin + ", paste(c(covariates, "pcttw\_sanders16"), collapse = " + "), " \textbar DMA\_CODE \textbar 0 \textbar DMA\_CODE")} & \multicolumn{3}{c}{paste0("scale(pcttw\_sanders) \textasciitilde treatBin + ", paste(c(covs, "pcttw\_sanders16"), collapse = " + "), " \textbar DMA\_CODE \textbar 0 \textbar DMA\_CODE")} \\ +\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6)\\ +\hline \\[-1.8ex] + Exposure Dummy & $-$1.068$^{**}$ & $-$0.482$^{*}$ & $-$0.994$^{**}$ & $-$0.943$^{**}$ & $-$0.656$^{*}$ & $-$0.940$^{**}$ \\ + & (0.387) & (0.230) & (0.338) & (0.325) & (0.296) & (0.323) \\ + & & & & & & \\ + LTHS & $-$0.038 & $-$0.040 & $-$0.083 & $-$0.062 & 0.135 & $-$0.014 \\ + & (0.049) & (0.123) & (0.113) & (0.054) & (0.179) & (0.116) \\ + & & & & & & \\ + Coll. Up & 0.019 & 0.147 & 0.070 & $-$0.0003 & 0.159 & $-$0.018 \\ + & (0.052) & (0.207) & (0.067) & (0.041) & (0.121) & (0.075) \\ + & & & & & & \\ + Lt30yo & $-$0.052 & $-$0.309$^{\dag}$ & $-$0.044 & $-$0.055 & $-$0.372$^{**}$ & $-$0.005 \\ + & (0.049) & (0.165) & (0.062) & (0.034) & (0.140) & (0.060) \\ + & & & & & & \\ + 60up & $-$0.175$^{***}$ & $-$0.257 & $-$0.176$^{**}$ & $-$0.218$^{***}$ & $-$0.450$^{***}$ & $-$0.185$^{***}$ \\ + & (0.049) & (0.180) & (0.054) & (0.043) & (0.100) & (0.053) \\ + & & & & & & \\ + Below poverty level & 0.041 & 0.086 & 0.042 & 0.037 & 0.111 & 0.053 \\ + & (0.030) & (0.104) & (0.050) & (0.031) & (0.106) & (0.056) \\ + & & & & & & \\ + Female HH no hus & $-$0.023 & $-$0.013 & 0.055 & $-$0.034 & $-$0.149 & $-$0.009 \\ + & (0.037) & (0.075) & (0.057) & (0.037) & (0.214) & (0.048) \\ + & & & & & & \\ + Unem rate & $-$0.020 & 0.285$^{\dag}$ & $-$0.019 & $-$0.026 & 0.094 & 0.002 \\ + & (0.024) & (0.158) & (0.040) & (0.027) & (0.077) & (0.044) \\ + & & & & & & \\ + LFPR & 0.057 & 0.012 & $-$0.017 & 0.051 & $-$0.073 & $-$0.008 \\ + & (0.040) & (0.149) & (0.039) & (0.040) & (0.153) & (0.044) \\ + & & & & & & \\ + Manufacturing & $-$0.040 & 0.154$^{\dag}$ & 0.005 & $-$0.054$^{*}$ & 0.195$^{**}$ & $-$0.019 \\ + & (0.031) & (0.086) & (0.042) & (0.022) & (0.073) & (0.044) \\ + & & & & & & \\ + Med HH Inc & $-$0.149$^{**}$ & 0.052 & $-$0.139$^{*}$ & $-$0.192$^{***}$ & $-$0.097 & $-$0.075 \\ + & (0.048) & (0.189) & (0.065) & (0.053) & (0.141) & (0.073) \\ + & & & & & & \\ + Rural & $-$0.031 & $-$0.039 & $-$0.030 & $-$0.014 & $-$0.089 & $-$0.002 \\ + & (0.021) & (0.068) & (0.043) & (0.020) & (0.170) & (0.044) \\ + & & & & & & \\ + Speak only english & $-$0.195$^{***}$ & $-$0.295 & $-$0.229$^{**}$ & $-$0.217$^{***}$ & $-$0.251 & $-$0.183$^{*}$ \\ + & (0.041) & (0.235) & (0.086) & (0.044) & (0.227) & (0.087) \\ + & & & & & & \\ + White & 0.069 & $-$0.279 & 0.100$^{*}$ & 0.071 & $-$0.371$^{\dag}$ & 0.106$^{\dag}$ \\ + & (0.050) & (0.225) & (0.045) & (0.055) & (0.211) & (0.055) \\ + & & & & & & \\ + Black & $-$0.083 & $-$0.380 & 0.002 & $-$0.135$^{*}$ & $-$0.644$^{*}$ & 0.069 \\ + & (0.052) & (0.375) & (0.076) & (0.060) & (0.285) & (0.091) \\ + & & & & & & \\ + Tot pop & 0.025 & 0.094 & 0.006 & 0.039 & $-$0.013 & 0.026 \\ + & (0.025) & (0.062) & (0.024) & (0.028) & (0.072) & (0.027) \\ + & & & & & & \\ + Turnout 2020 & 0.135$^{***}$ & 0.020 & 0.070 & 0.201$^{***}$ & 0.515$^{*}$ & 0.203$^{***}$ \\ + & (0.034) & (0.267) & (0.063) & (0.024) & (0.207) & (0.041) \\ + & & & & & & \\ + Caucus switch & $-$0.024 & 0.279 & 0.693$^{*}$ & & & \\ + & (0.679) & (1.130) & (0.332) & & & \\ + & & & & & & \\ + Pcttw sanders16 & 0.026$^{***}$ & 0.051$^{**}$ & 0.032$^{***}$ & 0.026$^{***}$ & 0.044$^{***}$ & 0.036$^{***}$ \\ + & (0.004) & (0.016) & (0.005) & (0.004) & (0.010) & (0.005) \\ + & & & & & & \\ +\hline \\[-1.8ex] +Observations & 1,882 & 375 & 1,882 & 1,710 & 304 & 1,710 \\ +R$^{2}$ & 0.817 & 0.803 & 0.899 & 0.860 & 0.898 & 0.924 \\ +\hline +\hline \\[-1.8ex] +\textit{Note:} & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ +\end{tabular} +\end{table} diff --git a/29/replication_package/Tables/table1.tex b/29/replication_package/Tables/table1.tex new file mode 100644 index 0000000000000000000000000000000000000000..f65a4451d699942e42e90003707060a21965e76b --- /dev/null +++ b/29/replication_package/Tables/table1.tex @@ -0,0 +1,37 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Thu, Jun 17, 2021 - 12:52:24 AM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}}lcccccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & \multicolumn{6}{c}{\textit{Dependent variable:}} \\ +\cline{2-7} +\\[-1.8ex] & \multicolumn{6}{c}{paste0("scale(pcttw\_sanders) \textasciitilde treatBin + ", paste(c(covariates, "pcttw\_sanders16"), collapse = " + "), " \textbar DMA\_CODE \textbar 0 \textbar DMA\_CODE")} \\ +\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6)\\ +\hline \\[-1.8ex] + Exposure Dummy & $-$1.321$^{*}$ & $-$1.064$^{*}$ & $-$1.348$^{***}$ & $-$0.885$^{*}$ & $-$0.569$^{**}$ & $-$0.885$^{**}$ \\ + & (0.552) & (0.477) & (0.380) & (0.382) & (0.200) & (0.325) \\ + & & & & & & \\ + Turnout 2020 & 0.175$^{***}$ & 0.179$^{**}$ & 0.137$^{***}$ & 0.197$^{***}$ & 0.225$^{***}$ & 0.169$^{***}$ \\ + & (0.026) & (0.056) & (0.038) & (0.026) & (0.052) & (0.041) \\ + & & & & & & \\ + Sanders 2016 & 0.027$^{***}$ & 0.030$^{***}$ & 0.032$^{***}$ & 0.026$^{***}$ & 0.033$^{***}$ & 0.034$^{***}$ \\ + & (0.004) & (0.006) & (0.006) & (0.004) & (0.006) & (0.006) \\ + & & & & & & \\ + Caucus switch & 0.628 & 0.897$^{*}$ & 0.874 & 0.205 & 0.730 & 0.764 \\ + & (0.959) & (0.397) & (0.557) & (0.771) & (0.586) & (0.465) \\ + & & & & & & \\ + Caucus dummy & 1.227$^{***}$ & 0.337 & 0.764$^{\dag}$ & & & \\ + & (0.221) & (0.469) & (0.417) & & & \\ + & & & & & & \\ +\hline \\[-1.8ex] +Observations & 1,882 & 666 & 1,882 & 1,710 & 666 & 1,710 \\ +R$^{2}$ & 0.830 & 0.894 & 0.883 & 0.860 & 0.900 & 0.898 \\ +\hline +\hline \\[-1.8ex] +\textit{Note:} & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ +\end{tabular} +\end{table} \ No newline at end of file diff --git a/29/replication_package/Tables/table2.tex b/29/replication_package/Tables/table2.tex new file mode 100644 index 0000000000000000000000000000000000000000..77f986948d0ae1adeaa7558b4de48074f77a865e --- /dev/null +++ b/29/replication_package/Tables/table2.tex @@ -0,0 +1,43 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Thu, Jun 17, 2021 - 12:52:31 AM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}}lcccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & \multicolumn{4}{c}{\textit{Dependent variable:}} \\ +\cline{2-5} +\\[-1.8ex] & \multicolumn{4}{c}{yBin} \\ +\\[-1.8ex] & (1) & (2) & (3) & (4)\\ +\hline \\[-1.8ex] + Anxiety Prime & $-$0.074$^{\dag}$ & $-$0.078$^{*}$ & $-$0.082$^{*}$ & $-$0.182$^{**}$ \\ + & (0.039) & (0.038) & (0.038) & (0.061) \\ + & & & & \\ + Democrat & & $-$0.133$^{*}$ & $-$0.133$^{*}$ & $-$0.076 \\ + & & (0.061) & (0.060) & (0.098) \\ + & & & & \\ + Lean Dem & & $-$0.047 & $-$0.054 & 0.032 \\ + & & (0.072) & (0.071) & (0.112) \\ + & & & & \\ + Independent & & $-$0.071 & $-$0.070 & 0.083 \\ + & & (0.063) & (0.062) & (0.104) \\ + & & & & \\ + Lean GOP & & $-$0.311$^{***}$ & $-$0.329$^{***}$ & $-$0.308$^{*}$ \\ + & & (0.080) & (0.079) & (0.123) \\ + & & & & \\ + Republican & & $-$0.383$^{***}$ & $-$0.385$^{***}$ & $-$0.244$^{*}$ \\ + & & (0.074) & (0.073) & (0.118) \\ + & & & & \\ + Strong GOP & & $-$0.294$^{***}$ & $-$0.296$^{***}$ & $-$0.121 \\ + & & (0.081) & (0.080) & (0.131) \\ + & & & & \\ +\hline \\[-1.8ex] +Observations & 654 & 654 & 654 & 269 \\ +R$^{2}$ & 0.006 & 0.095 & 0.117 & 0.147 \\ +\hline +\hline \\[-1.8ex] +\textit{Note:} & \multicolumn{4}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ +\end{tabular} +\end{table} diff --git a/29/replication_package/Tables/table3.tex b/29/replication_package/Tables/table3.tex new file mode 100644 index 0000000000000000000000000000000000000000..46bca3cf87099c33f83ff1b3bcd448445e17c432 --- /dev/null +++ b/29/replication_package/Tables/table3.tex @@ -0,0 +1,32 @@ + +% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu +% Date and time: Thu, Jun 17, 2021 - 12:52:32 AM +\begin{table}[!htbp] \centering + \caption{} + \label{} +\begin{tabular}{@{\extracolsep{5pt}}lccc} +\\[-1.8ex]\hline +\hline \\[-1.8ex] + & \multicolumn{3}{c}{\textit{Dependent variable:}} \\ +\cline{2-4} +\\[-1.8ex] & \multicolumn{3}{c}{voteSh} \\ +\\[-1.8ex] & (1) & (2) & (3)\\ +\hline \\[-1.8ex] + Anti-Est. & 0.342$^{***}$ & 0.134$^{**}$ & 0.364$^{***}$ \\ + & (0.043) & (0.050) & (0.043) \\ + & & & \\ + Cases (ln) & $-$0.044 & $-$0.014 & $-$0.031 \\ + & (0.150) & (0.151) & (0.151) \\ + & & & \\ + Anti-Est. X Cases (ln) & $-$0.016$^{**}$ & 0.014 & $-$0.020$^{**}$ \\ + & (0.006) & (0.012) & (0.006) \\ + & & & \\ +\hline \\[-1.8ex] +District FE & Y & Y & Y \\ +Observations & 2,019 & 2,019 & 2,019 \\ +R$^{2}$ & 0.516 & 0.506 & 0.515 \\ +\hline +\hline \\[-1.8ex] +\textit{Note:} & \multicolumn{3}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ +\end{tabular} +\end{table} diff --git a/29/replication_package/_NOTETOEDITOR b/29/replication_package/_NOTETOEDITOR new file mode 100644 index 0000000000000000000000000000000000000000..effe907cd094d7def04658de6cbe89fa4f6da3a5 --- /dev/null +++ b/29/replication_package/_NOTETOEDITOR @@ -0,0 +1,18 @@ +FOR THE EDITOR / REPLICATOR: +In assembling the replication materials, we identified a handful of small changes to the empirical results. Of these, only one appears in the body of the paper and is a vanishingly small difference from the previous draft that we submitted. The remainder appear in the Supporting Information and are attributable to setting a random seed for replication, identifying an error in the code for one of the tables, identifying an error in one of the DMA shapefiles, and identifying an error in a function of a third party package we used. Importantly, none of these changes impact the substantive conclusion of our results. We describe each in detail below. + +MANUSCRIPT: +- Figure 4: We identified an error in one of the DMA shapefiles which affected the vanilla diff-in-diff specification. The substantive interpretation of the results hasn't changed, and the interaction coefficient estimate has moved from -6.75 (2.14) to -6.97 (2.15). + +SUPPORTING INFORMATION: +- Table SI-1: We identified an error in one of the DMA shapefiles which affected the comparison between dropped and kept counties in the FE specification. The substantive interpretation that these differences should work against our findings hasn't changed. Specifically, the Sanders 2016 voteshare differences have shifted from 39.9 / 46.2 / 0 / -8.9 to 39.7 / 46.1 / 0 / -8.9. + +- Figure SI-3: We hadn't set a seed for these permutation results in our previous submission. We have now done so, resulting in insignificantly different distributions than what was originally submitted. The substantive interpretation of these permutation tests hasn't changed. + +- SI page 15: We mistakenly reported that our choice of covariates left us with 152 observations for inference in the March subset. This number is actually 304 in the updated estimates contained in Table SI-5 (see note below) and should have been 370 in the previous draft. + +- Figure SI-13 & SI-14: We noticed an error in the calculation of the dashed lines for these plots in the original package function. We have fixed the error and notified the package author. It has no impact on our findings or conclusions (and indeed is almost imperceptible to the naked eye). + +- Figure SI-10: The inclusion of the caucus measures influenced the results displayed in this plot. The changes are very small (with the exception of the matched specification, they are basically identical) and do not influence the substantive conclusions. + +- Table SI-5: A mistake in our previous submission failed to add Sanders 2016 and the caucus indicators as controls. We have fixed this mistake, resulting in slightly different coefficients. None of the substantive interpretations are affected. \ No newline at end of file diff --git a/29/replication_package/_README b/29/replication_package/_README new file mode 100644 index 0000000000000000000000000000000000000000..b18b02fb4f81ac77c54e207c164680ecfc77205e --- /dev/null +++ b/29/replication_package/_README @@ -0,0 +1,18 @@ +The contents of this folder can be used to replicate all of the findings of , James Bisbee and Dan Honig, APSR. + +This folder follows the following structure: + +Replication.zip + |- Code + |- Data + |- Figures + |- Tables + +- Replication.zip: the main folder contains all datasets required to replicate tables and figures in the paper and online appendix. +- Code: pre-populated folder containing R scripts to generate the figures and tables. The scripts are named after the corresponding figure or table names indexed in the main manuscript and online appendix. Figures and table numbers prefixed with "SI" indicates outputs included in the online appendix. +- Figures: pre-populated folder storing figures in both main manuscript as well as online appendix. +- Tables: pre-populated folder storing regression tables in both main manuscript as well as online appendix. + +All analyses are conducted in R. All replications are produced using R version 3.6.3. + +Please contact James Bisbee (jhb362@nyu.edu) for questions. \ No newline at end of file diff --git a/29/should_reproduce.txt b/29/should_reproduce.txt new file mode 100644 index 0000000000000000000000000000000000000000..74ad8417c344b6fa890354c57da3fefbc59e73ec --- /dev/null +++ b/29/should_reproduce.txt @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:525b7abb504625a938797a477e498f756384d0aba0a8af873c60c4877e67cbc4 +size 18