This document contains the dataset needed and calculation for the intervention costs per woman receiving the intervention.
Library and settings
library(tidyverse)
library(readxl)
library(ggplot2)
#library(tabulizer)
library(rnaturalearth)
library(sf)
library(DT)
library(lhs)
library(stringr)
library(countrycode)
library(priceR)
Load in dataset
load(file="data/cost.RData")
bind_elements_into_df <- function(lst, start_idx, end_idx) {
result_df <- as.data.frame(lst[[start_idx]])
for (i in (start_idx + 1):end_idx) {
result_df <- rbind(result_df, as.data.frame(lst[[i]]))
}
return(result_df)
}
tanc=read_excel("/Users/hec442/Desktop/harvard/calcium/data/who-choice-estimates-of-cost-for-inpatient-and-outpatient-health-service-delivery.xlsx")
top= bind_elements_into_df(cost, 55, 59)
colnames(top) <- c("country", "health_nobed", "health_bed", "primary", "secondary", "tertiary")
inflat = read_excel("/Users/hec442/Desktop/harvard/calcium/data/API_NY.GDP.DEFL.ZS.AD_DS2_en_excel_v2_5730570.xls", sheet = 1, skip = 2) %>%
janitor::clean_names() %>%
select(country_name, country_code, x2010, x2011, x2012, x2013, x2014, x2015, x2016, x2017, x2018, x2019, x2020, x2021, x2022 )
inflat= inflat %>%
mutate(across(x2010:x2022, ~.*0.01),
across(everything(), ~replace_na(., 1)),
acc_inf = apply(inflat[, 3:ncol(inflat)], 1, prod)) %>%
select(country_name, country_code,acc_inf)
datatable(
data = inflat,
caption = "Table 1: Inflation from 2010 to 2022",
filter = "top",
style = "bootstrap4"
)
currency <- data.frame(curencycode = character(0), rate = numeric(0))
currency_23 = exchange_rate_latest("USD")
## Daily USD exchange rate as at end of day 2023-09-15 GMT
# Iterate through each currency code
for (i in 1:nrow(currency_23)) {
currency_code <- currency_23$currency[i]
exchange_rates <- historical_exchange_rates(currency_code, to = "USD",
start_date = "2010-01-01", end_date = "2010-12-30")
colnames(exchange_rates) <- c("date", "rate")
median_rate <- median(exchange_rates$rate, na.rm = TRUE)
currency <- rbind(currency, data.frame(currencycode = currency_code, rate = median_rate))
}
currency= currency %>%
left_join(currency_23, by =c("currencycode"= "currency")) %>%
rename(rate_10 = rate,
rate_23 = one_usd_is_equivalent_to)
datatable(
data = currency,
caption = "Table 2: Currency use for 2010",
filter = "top",
style = "bootstrap4"
)
anc_cost = tanc %>%
janitor::clean_names() %>%
mutate(iso3 = countrycode(country, "country.name", "iso3c"),
currency_code = countrycode(iso3, origin = 'iso3c', destination = 'iso4217c')) %>%
left_join(currency, by= c("currency_code"="currencycode")) %>%
# for the rate 2010 is one local currency = x usd, so it should be usd/ rate2010
mutate( primary_local_10 = primary_hospital/rate_10) %>%
left_join(inflat, by=c("iso3"="country_code")) %>%
# for the rate 2023 is one usd = x local currency, so it should be local currecy/rate 2023
mutate(inf_primary = primary_local_10*acc_inf,
inf_usd = inf_primary/rate_23)
datatable(
data = anc_cost,
caption = "Table 3: The Unit cost of health services per antenatal visit",
filter = "top",
style = "bootstrap4"
)
top <- as.data.frame( lapply(top, function(x) gsub(" ", "", x)))
op_cost = top %>%
mutate(health_nobed=as.numeric(health_nobed),
health_bed=as.numeric(health_bed),
primary=as.numeric(primary),
secondary=as.numeric(secondary),
tertiary=as.numeric(tertiary),
iso3 = countrycode(country, "country.name", "iso3c"),
currency_code = countrycode(iso3, origin = 'iso3c', destination = 'iso4217c')) %>%
left_join(currency, by= c("currency_code"="currencycode")) %>%
# for the rate 2010 is one local currency = x usd, so it should be usd/ rate2010
mutate(primary_local_10 = primary/rate_10) %>%
left_join(inflat, by=c("iso3"="country_code")) %>%
# for the rate 2023 is one usd = x local currency, so it should be local currecy/rate 2023
mutate(inf_primary = primary_local_10*acc_inf,
inf_usd = inf_primary/rate_23)
datatable(
data = op_cost,
caption = "Table 4: Unit cost of health services per non-ANC out-patient visit",
filter = "top",
style = "bootstrap4"
)
thre = read_excel("/Users/hec442/Desktop/harvard/calcium/data/costthreshold.xlsx") %>%
janitor::clean_names() %>%
mutate( iso3 = countrycode(country, "country.name", "iso3c"),
currency_code = countrycode(iso3, origin = 'iso3c', destination = 'iso4217c')) %>%
left_join(currency, by= c("currency_code"="currencycode")) %>%
left_join(inflat, by=c("iso3"="country_code")) %>%
mutate(daly1_local_10 = daly_1/rate_10,
daly2_local_10 = daly_2/rate_10,
daly3_local_10 = daly_3/rate_10,
daly4_local_10 = daly_4/rate_10,
inf_daly1 = daly1_local_10*acc_inf,
inf_daly2 = daly2_local_10*acc_inf,
inf_daly3 = daly3_local_10*acc_inf,
inf_daly4 = daly4_local_10*acc_inf,
inf_daly1_usd = inf_daly1/rate_23,
inf_daly2_usd = inf_daly1/rate_23,
inf_daly3_usd = inf_daly1/rate_23,
inf_daly4_usd = inf_daly1/rate_23) %>%
select(country, iso3, daly_1, daly1_local_10, inf_daly1, inf_daly1_usd, daly1_frac, daly_2, daly2_local_10, inf_daly2, inf_daly2_usd, daly2_frac, daly_3, daly3_local_10, inf_daly3, inf_daly3_usd, daly3_frac, daly_4, daly4_local_10, inf_daly4, inf_daly4_usd, daly4_frac )
datatable(
data = thre,
caption = "Table 5: Threshold for cost efficient",
filter = "top",
style = "bootstrap4"
)