thisbureau <- "Americas"
lastyear <- max(unhcrdatapackage::end_year_population_totals_long$Year)
topasyl <- unhcrdatapackage::asylum_decisions %>%
## Add reference for the filters
dplyr::left_join( unhcrdatapackage::reference %>%
select(coa_region = `UNHCRBureau`, iso_3), by = c("CountryAsylumCode" = "iso_3")) %>%
filter(coa_region == thisbureau & Year == lastyear) %>%
# select(region_asy, ctry_asy, year, recognizedConvMandate, recognizedOther, appliedDuringTheYear, meta_applicationAveragePersonsPerCase) %>%
mutate(DecisionsAveragePersonsPerCase = map_dbl(DecisionsAveragePersonsPerCase, ~replace_na(max(as.numeric(.), 1), 1))) %>%
group_by(CountryAsylumName) %>%
summarize(Recognized = sum(Recognized * DecisionsAveragePersonsPerCase, na.rm = TRUE),
ComplementaryProtection = sum(ComplementaryProtection * DecisionsAveragePersonsPerCase, na.rm = TRUE),
TotalDecided = sum(TotalDecided * DecisionsAveragePersonsPerCase, na.rm = TRUE)) %>%
mutate(RefugeeRecognitionRate = (Recognized ) / TotalDecided,
GlobalRecognitionRate = (Recognized + ComplementaryProtection) / TotalDecided ) %>%
filter(TotalDecided != 0) %>%
filter(TotalDecided > 1000) %>%
mutate(CountryAsylumName = str_replace(CountryAsylumName, "United States of America", "USA"))
topOrigin <- unhcrdatapackage::asylum_decisions %>%
## Add reference for the filters
dplyr::left_join( unhcrdatapackage::reference %>%
select(coa_region = `UNHCRBureau`, iso_3), by = c("CountryOriginCode" = "iso_3")) %>%
filter(coa_region == thisbureau & Year == lastyear) %>%
# select(region_asy, ctry_asy, year, recognizedConvMandate, recognizedOther, appliedDuringTheYear, meta_applicationAveragePersonsPerCase) %>%
mutate(DecisionsAveragePersonsPerCase = map_dbl(DecisionsAveragePersonsPerCase, ~replace_na(max(as.numeric(.), 1), 1))) %>%
group_by(CountryOriginName) %>%
summarize(Recognized = sum(Recognized * DecisionsAveragePersonsPerCase, na.rm = TRUE),
ComplementaryProtection = sum(ComplementaryProtection * DecisionsAveragePersonsPerCase, na.rm = TRUE),
TotalDecided = sum(TotalDecided * DecisionsAveragePersonsPerCase, na.rm = TRUE)) %>%
mutate(RefugeeRecognitionRate = (Recognized ) / TotalDecided,
GlobalRecognitionRate = (Recognized + ComplementaryProtection) / TotalDecided) %>%
filter(TotalDecided != 0) %>%
filter(TotalDecided > 1000) %>%
mutate(CountryOriginName = str_replace(CountryOriginName, " \\(Bolivarian Republic of\\)", ""))
topasyl2 <- topasyl %>%
arrange(desc(RefugeeRecognitionRate)) %>%
head(10)
## Filter top 10
topOrigin2 <- topOrigin %>%
arrange(desc(RefugeeRecognitionRate)) %>%
head(10)