# read in the latest data from the Oxford tracker and get rid of any sub-national data. (This is only available for the US, UK, Brazil, and Canada).
# According to the Oxford documentation the variable E1_Income_Support indicates 
# whether the government provides cash support. The E1_Flag variable indicates whether the support is geographically targeted or not.
oxford <- read_csv("https://raw.githubusercontent.com/OxCGRT/covid-policy-tracker/master/data/OxCGRT_latest.csv") %>% select(code = CountryCode, inc_supp = `E1_Income support`, inc_support_geo_targ = E1_Flag, Date, Jurisdiction) %>% 
  filter(Jurisdiction == "NAT_TOTAL")

# read in our in our dataset
infra <- read_csv(here("Data", "Clean", "country payments and id infra.csv")) 

Plot the number of countries with active income support programs over time from the Oxford data.

# clean up the date variable and generate new variable for whether any income support
oxford <- oxford %>% mutate(Date = ymd(Date), any_ct = (inc_supp > 0))

# generate the total number of cash transfers by date
ct_by_date <- oxford %>% filter(any_ct) %>% count(Date) %>% arrange(Date)

# show the number of cash transfers by date 
ggplot(ct_by_date, aes(Date, n)) + geom_line() +
  labs(y = "# countries with active income support program", title = "# countries with active income support over time")

Look at the correlation between whether a country was flagged as ever having an income support program in the Oxford dataset and whether there are any CT programs listed in the G2P dataset for the country.

# generate dataframe for whether a country ever had an income support program
ever_inc <- oxford %>% group_by(code) %>% summarize(oxford_ct = max(any_ct, na.rm = TRUE))

# merge with the G2P data
merged <- infra %>% inner_join(ever_inc, by = "code") %>% 
  replace_na(list(m21_bens_actual = 0)) %>% 
  mutate(g2p_ct = as.numeric(m21_bens_actual > 0)) %>% 
  select(code, oxford_ct, g2p_ct) %>% 
  mutate(oxford_ct = if_else(oxford_ct == -Inf, 0, oxford_ct))

cor(merged$g2p_ct, merged$oxford_ct)
## [1] 0.0261145