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") %>% |
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(treemapify) | |
library(countrycode) | |
library(gganimate) | |
library(magick) | |
# devtools::install_github("PPgp/wpp2022") | |
library(wpp2022) | |
# load data | |
data(pop1dt) |
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
name | region | order | colour | gap | name_zh | |
---|---|---|---|---|---|---|
Beijing | East | 1 | #B61416 | 2 | 北京 | |
Tianjin | East | 2 | #C01517 | 2 | 天津 | |
Hebei | East | 3 | #CA1718 | 2 | 河北 | |
Shandong | East | 4 | #D4181A | 2 | 山东 | |
Jiangsu | East | 5 | #DE191B | 2 | 江苏 | |
Shanghai | East | 6 | #E91A1C | 2 | 上海 | |
Zhejiang | East | 7 | #F31B1D | 2 | 浙江 | |
Fujian | East | 8 | #FD1C1F | 2 | 福建 | |
Guangdong | East | 9 | #FF1E20 | 2 | 广东 |
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
orig | dest | flow | |
---|---|---|---|
Beijing | Beijing | 0 | |
Tianjin | Beijing | 67355 | |
Hebei | Beijing | 864387 | |
Shanxi | Beijing | 225032 | |
Inner Mongolia | Beijing | 103355 | |
Liaoning | Beijing | 155032 | |
Jilin | Beijing | 104774 | |
Heilongjiang | Beijing | 194387 | |
Shanghai | Beijing | 26581 |
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) | |
library(tweenr) | |
library(ggforce) | |
library(gridExtra) | |
library(animation) | |
library(magick) | |
# download the migrant stock origin-destination xlsx file from the UN site | |
x <- tempfile(fileext = ".xlsx") |
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
ipums_clean_dta <- function( | |
d = NULL, numeric_convert = NULL, string_as_factors = TRUE, clean_labels = FALSE, | |
mis_lab = c("unknown", "niu (not in universe)", "not reported/missing", | |
"unknown/missing", "response suppressed", "unclassifiable") | |
){ | |
d %>% | |
{if(clean_labels) dplyr::mutate_if(is.labelled, ipumsr::lbl_clean) else .} %>% | |
dplyr::mutate_if(is.labelled, ~ipumsr::lbl_na_if(., ~.lbl %in% mis_lab)) %>% | |
dplyr::mutate_at({numeric_convert}, haven::zap_labels) %>% | |
dplyr::mutate_if(is.labelled, haven::as_factor) %>% |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<table> | |
<tbody> | |
<tr> |
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
## ----setup, include=FALSE------------------------------------------------ | |
library(knitr) | |
knitr::opts_chunk$set(prompt= TRUE, collapse = TRUE, comment = NA) | |
knitr::opts_chunk$set(fig.width = 5, fig.height = 5) | |
knitr::knit_hooks$set(purl = hook_purl) | |
## ---- message=FALSE------------------------------------------------------ | |
# install.packages("migest") | |
library(tidyverse) | |
d0 <- read_csv(system.file("imr", "reg_flow.csv", package = "migest")) |
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
age | x | Nx_m | Nx_f | Lx_m | Lx_f | Fx | Mx_f | |
---|---|---|---|---|---|---|---|---|
00--05 | 0 | 310189 | 293395 | 496754 | 497487 | 0 | 6840 | |
05--10 | 5 | 261963 | 248369 | 496297 | 497138 | 0 | 4150 | |
10--15 | 10 | 252046 | 240012 | 495989 | 496901 | 0 | 3365 | |
15--20 | 15 | 274711 | 261346 | 495113 | 496531 | 0.012 | 5270 | |
20--25 | 20 | 296679 | 285209 | 493460 | 495902 | 0.0908 | 9240 | |
25--30 | 25 | 333726 | 314388 | 491475 | 495168 | 0.1499 | 8230 | |
30--35 | 30 | 296774 | 281290 | 489325 | 494213 | 0.1125 | 5470 | |
35--40 | 35 | 299391 | 286923 | 486487 | 492760 | 0.0441 | 3155 | |
40--45 | 40 | 314295 | 304108 | 482392 | 490447 | 0.0074 | 1770 |
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
\documentclass[11pt]{report} | |
\usepackage[a4paper,margin=2cm, bindingoffset=2cm]{geometry} | |
\usepackage{appendix} | |
\usepackage{amsmath} | |
\usepackage{booktabs} | |
\usepackage{threeparttable} | |
\usepackage{natbib} | |
\bibliographystyle{chicago} |