| |
| |
| |
| |
| setwd(getOption("replication.root", default = getwd())); options(error = NULL) |
| library(dplyr) |
| library(tidyr) |
| library(ggplot2) |
|
|
| KeepObjectsAcrossAnalysisStrings <- get0("KeepObjectsAcrossAnalysisStrings", ifnotfound = character()) |
| try(rm(list=ls()[!ls() %in% (Keeps <- c("t0",KeepObjectsAcrossAnalysisStrings))] ),T) |
|
|
| |
| treat_control_actual_dhs_df <- read.csv("./data/interim/dhs_treat_control_3yr_actual_counts.csv") |
|
|
| |
| |
| |
| |
| dhs_confounders_df <- read.csv("./data/interim/dhs_5k_confounders.csv") %>% |
| dplyr::select(-year) |
|
|
| |
| |
| dhs_iso3_df <- dhs_confounders_df %>% |
| distinct(dhs_id,iso3) |
|
|
| |
| dhs_t_df <- read.csv("./data/interim/dhs_treated_sector_3yr.csv") %>% |
| |
| inner_join(dhs_confounders_df %>% |
| dplyr::select(dhs_id, ID_adm2), by = join_by(dhs_id)) %>% |
| filter(year_group!="2014:2016") |
|
|
| |
| |
| funder_sector_iso3 <- dhs_t_df %>% |
| |
| inner_join(dhs_confounders_df, by="dhs_id") %>% |
| distinct(funder,sector,iso3) |
| |
| |
| year_group_v <- c('2002:2004', '2005:2007', '2008:2010', '2011:2013') |
|
|
| |
| all_t_c_df <- funder_sector_iso3 %>% |
| |
| crossing(year_group = year_group_v) %>% |
| |
| left_join(dhs_iso3_df,by="iso3", |
| multiple = "all") |
|
|
| |
| dhs_c_df <- all_t_c_df %>% |
| |
| anti_join(dhs_t_df,by=c("sector","funder","dhs_id","year_group")) |
|
|
| treat_dhs_count_df <- dhs_t_df %>% |
| group_by(funder,sector) %>% |
| summarize(treat_n = n()) %>% |
| ungroup() |
|
|
| control_dhs_count_df <- dhs_c_df %>% |
| group_by(funder,sector) %>% |
| summarize(control_n = n()) %>% |
| ungroup() |
|
|
| |
| treat_control_est_dhs_df <- treat_dhs_count_df %>% |
| left_join(control_dhs_count_df, by=c("funder","sector")) %>% |
| rename(est_iwi_treat_n = treat_n, |
| est_iwi_control_n = control_n) |
|
|
| |
| t_c_est_act_df <- treat_control_est_dhs_df %>% |
| left_join(treat_control_actual_dhs_df, by=c("funder","sector")) %>% |
| rename(act_iwi_treat_n = treat_n, |
| act_iwi_control_n = control_n) %>% |
| mutate(act_iwi_treat_n = ifelse(is.na(act_iwi_treat_n),0,act_iwi_treat_n), |
| act_iwi_control_n = ifelse(is.na(act_iwi_control_n),0,act_iwi_control_n)) |
|
|
| write.csv(t_c_est_act_df,"./tables/dhs_treat_control_est_act_compare.csv",row.names=FALSE) |
|
|
| |
| sector_names_df <- read.csv("./data/interim/sector_group_names.csv") %>% |
| mutate(sec_pre_name = paste0(ad_sector_names," (",ad_sector_codes,")")) %>% |
| dplyr::select(ad_sector_codes, sec_pre_name) |
|
|
| t_c_est_act_display_df <- t_c_est_act_df %>% |
| left_join(sector_names_df,join_by(sector==ad_sector_codes)) %>% |
| pivot_longer( |
| cols = c(est_iwi_treat_n, est_iwi_control_n, act_iwi_treat_n, act_iwi_control_n), |
| names_to = "count_name", |
| values_to = "count_obs" |
| ) %>% |
| unite("funder_count_name", funder, count_name, sep = "_") %>% |
| pivot_wider( |
| names_from = funder_count_name, |
| values_from = count_obs |
| ) %>% |
| dplyr::select(-sector) |
| |
| |
| write.csv(t_c_est_act_display_df,"./tables/dhs_treat_control_est_act_display.csv",row.names=FALSE) |
|
|
| |
| |
| |
|
|
| |
| max_abs_value <- max(abs(t_c_est_act_df$est_iwi_treat_n), |
| abs(t_c_est_act_df$act_iwi_treat_n), |
| na.rm=T) |
|
|
| treated_est_act <- t_c_est_act_df %>% |
| ggplot(aes(x = act_iwi_treat_n, y = est_iwi_treat_n, color=funder, |
| label=sector)) + |
| geom_point() + |
| ggrepel::geom_text_repel(box.padding = .1,max.overlaps=Inf,show.legend=FALSE) + |
| scale_color_manual(name = "Funder", |
| values = c("ch"="indianred1","wb"="mediumblue"), |
| labels = c("China","World Bank")) + |
| geom_abline(intercept=0, slope=1, linetype="dashed",color="gray80") + |
| labs(title = "Treated Observations: Actual DHS Versus Estimated Wealth Outcomes\nBy Funder and Sector Number", |
| x = "Actual DHS Wealth Data Treated Number (Cross-Sectional Data)", |
| y = "Estimated Wealth Data Treated Number (Panel Data)", |
| legend = "Funder") + |
| coord_cartesian(xlim=c(0,max_abs_value), |
| ylim=c(0,max_abs_value)) + |
| theme_bw() + |
| theme(panel.grid = element_blank()) |
|
|
| |
| ggsave("./figures/xy_treated_n_est_act.pdf", |
| treated_est_act, |
| width=8, height = 6, dpi=300, |
| bg="white", units="in") |
|
|
|
|
| |
| max_abs_value_tc <- max(abs(t_c_est_act_df$est_iwi_treat_n), |
| abs(t_c_est_act_df$act_iwi_treat_n), |
| abs(t_c_est_act_df$est_iwi_control_n), |
| abs(t_c_est_act_df$act_iwi_control_n), |
| na.rm=T) |
|
|
| t_c_est_act_fig <- t_c_est_act_df %>% |
| pivot_longer(cols=starts_with("est"),names_to="var_est",values_to="estimated_n") %>% |
| mutate(var=ifelse(grepl("_iwi_treat_n",var_est),"Treated","Control")) %>% |
| dplyr::select(-var_est) %>% |
| mutate(actual_n=ifelse(var=="Treated",act_iwi_treat_n,act_iwi_control_n)) %>% |
| dplyr::select(-act_iwi_treat_n,-act_iwi_control_n ) %>% |
| ggplot(aes(x = actual_n, y = estimated_n, color=funder, |
| label=sector)) + |
| facet_wrap(var ~ funder,scales="free", |
| labeller=labeller(funder=c("ch"="China","wb"="World Bank"))) + |
| geom_point(show.legend=FALSE) + |
| ggrepel::geom_text_repel(box.padding = .1,max.overlaps=Inf,show.legend=FALSE) + |
| scale_color_manual(values = c("ch"="indianred1","wb"="mediumblue"), |
| labels = c("China","World Bank")) + |
| geom_abline(intercept=0, slope=1, linetype="dashed",color="gray80") + |
| labs(title = "Observation Number With Actual DHS Versus Estimated Wealth Outcomes\nBy Funder and Sector Number", |
| x = "Actual DHS Wealth Data Observations (Cross-Sectional Data)", |
| y = "Estimated Wealth Data Observations (Panel Data)", |
| legend = "Funder") + |
| theme_bw() + |
| theme(panel.grid = element_blank()) |
|
|
| |
| ggsave("./figures/xy_cntrl_treated_n_est_act.pdf", |
| t_c_est_act_fig, |
| width=8, height = 8, dpi=300, |
| bg="white", units="in") |
|
|