| |
| library(dplyr) |
| library(tidyr) |
|
|
| KeepObjectsAcrossAnalysisStrings <- get0("KeepObjectsAcrossAnalysisStrings", ifnotfound = character()) |
| rm(list=ls()[!ls() %in% (Keeps <- c("t0",KeepObjectsAcrossAnalysisStrings))] ) |
| setwd(getOption("replication.root", default = getwd())) |
|
|
| |
| |
| |
| oda_sect_group_df <- read.csv("./data/interim/africa_oda_sector_group.csv") %>% |
| filter(transactions_start_year >= 2002 & |
| transactions_start_year <= 2013) |
|
|
| donor_precision_count <- oda_sect_group_df %>% |
| group_by(funder, precision_code) %>% |
| summarize(n = n_distinct(project_location_id)) %>% |
| pivot_wider(names_from = funder, values_from = n, values_fill = 0) %>% |
| mutate(precision_code = paste("project_precision",precision_code)) %>% |
| rename(description = precision_code) |
|
|
| donor_vars_df <- oda_sect_group_df %>% |
| dplyr::select(funder, project_id, project_location_id, site_iso3, ad_sector_codes) %>% |
| group_by(funder) %>% |
| summarize(across(everything(), ~n_distinct(.))) %>% |
| pivot_longer(cols = -funder, names_to = "description", values_to = "distinct_count") %>% |
| pivot_wider(names_from = funder, values_from = distinct_count, values_fill = 0) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| no_end_date_df <- oda_sect_group_df %>% |
| dplyr::select(funder,end_actual_isodate) %>% |
| group_by(funder) %>% |
| summarize(portion_no_end_date = mean(end_actual_isodate=="")) %>% |
| mutate(portion_no_end_date = round(portion_no_end_date,2)) %>% |
| pivot_longer(cols = -funder, names_to = "description", values_to = "distinct_count") %>% |
| pivot_wider(names_from = funder, values_from = distinct_count, values_fill = 0) |
|
|
| no_funding_df <- oda_sect_group_df %>% |
| dplyr::select(funder,total_disbursements) %>% |
| group_by(funder) %>% |
| summarize(portion_no_funding = mean(is.na(total_disbursements))) %>% |
| mutate(portion_no_funding = round(portion_no_funding,2)) %>% |
| pivot_longer(cols = -funder, names_to = "description", values_to = "distinct_count") %>% |
| pivot_wider(names_from = funder, values_from = distinct_count, values_fill = 0) |
|
|
| multisector_df <- oda_sect_group_df %>% |
| dplyr::select(funder, geoname_id, transactions_start_year, ad_sector_codes) %>% |
| group_by(funder, geoname_id, transactions_start_year, ad_sector_codes) %>% |
| count() %>% |
| group_by(funder) %>% |
| summarize(portion_multisector = mean(n > 1)) %>% |
| mutate(portion_multisector = round(portion_multisector,2)) %>% |
| pivot_longer(cols = -funder, names_to = "description", values_to = "distinct_count") %>% |
| pivot_wider(names_from = funder, values_from = distinct_count, values_fill = 0) |
|
|
| desired_order <- c(3, 4, 1, 2, 5, 6, 7, 8, 9, 10) |
| donor_comparison_df <- rbind(donor_vars_df,donor_precision_count, no_end_date_df, |
| no_funding_df, multisector_df) %>% |
| slice(match(desired_order, row_number())) %>% |
| mutate(description = case_match(description, |
| "site_iso3" ~ "Countries hosting projects count", |
| "ad_sector_codes" ~ "Sectors funded", |
| "project_id" ~ "Aid project count", |
| "project_location_id" ~ "Aid project location count", |
| "project_precision 1" ~ "Exact locations available (precision 1)", |
| "project_precision 2" ~ "Near (<25km) locations available (precision 2)", |
| "project_precision 3" ~ "ADM2 locations available (precision 3)", |
| "portion_no_end_date" ~ "Portion lacking end date", |
| "portion_no_funding" ~ "Portion lacking funding information", |
| "portion_multisector" ~ "Portion with concurrent, co-located, multi-sector projects", |
| .default = description)) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| write.csv(donor_comparison_df,"./tables/funder_comparison.csv",row.names = FALSE) |
|
|
| |
| |
| oda_sect_group_df %>% |
| filter(precision_code < 4) %>% |
| group_by(funder, ad_sector_codes, ad_sector_names) %>% |
| count() |
|
|
|
|
| |
| |
| |
| |
| dhs_est_iwi_df <- read.csv("./data/interim/dhs_est_iwi.csv") |
|
|
| |
| dhs_confounders_df <- read.csv("./data/interim/dhs_5k_confounders.csv") |
|
|
| |
| excluded_dhs_df <- anti_join(dhs_est_iwi_df,dhs_confounders_df,by="dhs_id") %>% |
| group_by(iso3) %>% count() %>% ungroup() %>% |
| rename(n_excluded=n) |
|
|
| |
| africa_isos_df <- read.csv("./data/interim/africa_isos.csv") |
|
|
| |
| dhs_t_df <- read.csv("./data/interim/dhs_treated_sector_3yr.csv") %>% |
| filter(year_group!="2014:2016") %>% |
| |
| inner_join(dhs_confounders_df %>% |
| dplyr::select(dhs_id, ID_adm2), by = join_by(dhs_id)) |
|
|
| |
| dhs_never_treated_df <- anti_join(dhs_confounders_df,dhs_t_df,by="dhs_id") %>% |
| group_by(iso3) %>% count() %>% rename(n_never_treated=n) %>% ungroup() |
|
|
| |
| neighborhoods_df <- dhs_confounders_df %>% |
| dplyr::select(iso3,survey_start_year,households,rural.x,dhs_id) %>% |
| group_by(iso3,survey_start_year) %>% |
| summarize(n_cluster_locations=n_distinct(dhs_id), |
| n_households=sum(households), |
| portion_rural=round(mean(rural.x),2)) %>% |
| ungroup() %>% |
| |
| left_join(dhs_never_treated_df, by="iso3") %>% |
| mutate(n_never_treated=ifelse(is.na(n_never_treated),0,n_never_treated)) %>% |
| mutate(portion_never_treated=round(n_never_treated/n_cluster_locations,2)) %>% |
| |
| left_join(excluded_dhs_df,by="iso3") %>% |
| mutate(n_excluded=ifelse(is.na(n_excluded),0,n_excluded)) %>% |
| |
| left_join(africa_isos_df %>% dplyr::select(-iso2), by="iso3") %>% |
| rename(country=name) %>% |
| dplyr::select(country,survey_start_year,n_cluster_locations,n_households, |
| portion_rural,portion_never_treated,n_excluded) %>% |
| arrange(country) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| write.csv(neighborhoods_df,"./tables/neighborhoods.csv",row.names = FALSE) |
|
|
| |
| total_dhs_n_df <- dhs_confounders_df %>% |
| dplyr::select(iso3,survey_start_year,households,dhs_id) %>% |
| summarize(n_cluster_locations=n_distinct(dhs_id), |
| n_households=sum(households), |
| n_countries=n_distinct(iso3), |
| n_start_year=n_distinct(survey_start_year) |
| ) |
| write.csv(total_dhs_n_df,"./tables/total_dhs_n.csv",row.names = FALSE) |
|
|
|
|
|
|
|
|
| |
|
|