Last active
October 12, 2023 01:54
-
-
Save guyabel/827fd512e6f6b52e366ded46e9c02fd3 to your computer and use it in GitHub Desktop.
Read in UN DESA bilateral stock data (2020) into R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(readxl) | |
download.file(url = "https://www.un.org/development/desa/pd/sites/www.un.org.development.desa.pd/files/undesa_pd_2020_ims_stock_by_sex_destination_and_origin.xlsx", | |
destfile = "undesa_pd_2020_ims_stock_by_sex_destination_and_origin.xlsx", mode = "wb") | |
d <- read_excel(path = "undesa_pd_2020_ims_stock_by_sex_destination_and_origin.xlsx", | |
sheet = 2, skip = 10, na = "..", guess_max = 1e5) %>% | |
select(-1, -3, -5) %>% | |
pivot_longer(cols = -(1:4), names_to = "year", values_to = "stock") %>% | |
rename("dest" = 1, | |
"dest_code" = 2, | |
"orig" = 3, | |
"orig_code" = 4) %>% | |
mutate(sex = rep(c("b", "m", "f"), each = 7, length.out = n()), | |
year = str_sub(year, end = 4)) | |
d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment