-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1-3_ghe-recode.R
61 lines (41 loc) · 2.02 KB
/
1-3_ghe-recode.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
### 1.3 GHE recode
# This script recodes the processed GHE cause of death data (i.e., limited to
# analysis countries in `1-1_country-eligibility.R`) so that causes of
# death are relevant for this analysis, mutually exclusive, and collectively
# exhaustive. This script relies a cause recode map created in
# `scr/non-init/ghe_recode.R`.
# 1 Loading data ----------------------------------------------------------
# Applying the standard project environment
applyEnv()
# Loading data
base::load("data/processed/ghe.rda")
base::load("data/processed/cause_recode_map.rda")
# 2 Recoding causes -------------------------------------------------------
temp1 <- full_join(ghe,
cause_recode_map %>% rename(ghecause = original_ghecause,
causename = original_causename),
by = c("ghecause", "causename"))
temp2 <- temp1 %>%
filter(!is.na(recoded_ghecause)) %>%
group_by(iso3, year, sex, age, recoded_ghecause, recoded_causename) %>%
summarize(dths = sum(dths), .groups = "drop")
ghe_recoded <- temp2 %>%
rename(ghecause = recoded_ghecause, causename = recoded_causename) %>%
ungroup()
# 3 Checking recode -------------------------------------------------------
# Original causes, with unused lower level causes omitted, with deaths
# summed by country, year, age, and sex
original <- temp1 %>%
filter(!is.na(recoded_ghecause)) %>%
group_by(iso3, year, sex, age) %>%
summarize(dths = sum(dths), .groups = "drop")
# Recoded causes with deaths summed by country, year, age, and sex
recoded <- temp2 %>%
group_by(iso3, year, sex, age) %>%
summarize(dths = sum(dths), .groups = "drop")
# Checking that deaths under original causes (with unused lower level causes
# omitted) equal deaths under recoded causes
check <- full_join(original, recoded, by = c("iso3", "year", "sex", "age")) %>%
filter(round(dths.x / dths.y) != 1)
# __+ ghe_recoded ---------------------------------------------------------
sarahSave("ghe_recoded", folder = "data/processed")