-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path00_data_prep_1_country_level_data.R
57 lines (45 loc) · 1.7 KB
/
00_data_prep_1_country_level_data.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
library(readxl)
w2 <- read_excel("data/00_data_prep.R_country_level_data_wave2.xlsx", na = "-999")
w3 <- read_excel("data/00_data_prep.R_country_level_data_wave3.xlsx", na = "-999")
library(tidyverse)
ntile_na <- function(var, ntile_n)
{
notna <- !is.na(var)
out <- rep(NA_real_,length(var))
out[notna] <- ntile(var[notna],ntile_n)
return(out)
}
w2$GDPPPP_q <- ntile_na(w2$GDPPPP,2)
unique(w2$GDPPPP_q)
w2$GDPPPP_q <- factor(w2$GDPPPP_q, levels = 1:2, labels = c("<med", ">med"))
unique(w2$GDPPPP_q)
w2$GINI_q <- ntile_na(w2$GINI,2)
unique(w2$GINI_q)
w2$GINI_q <- factor(w2$GINI_q, levels = 1:2, labels = c("<med", ">med"))
unique(w2$GINI_q)
w2 <- w2 %>% mutate(libD_q = ntile(LibD, 2))
unique(w2$libD_q)
w2$libD_q <- factor(w2$libD_q, levels = 1:2, labels = c("<med", ">med"))
unique(w2$libD_q)
w2 <- w2 %>% mutate(egaD_q = ntile(EgaD, 2))
unique(w2$egaD_q)
w2$egaD_q <- factor(w2$egaD_q, levels = 1:2, labels = c("<med", ">med"))
unique(w2$egaD_q)
w3$GDPPPP_q <- ntile_na(w3$GDPPPP,2)
unique(w3$GDPPPP_q)
w3$GDPPPP_q <- factor(w3$GDPPPP_q, levels = 1:2, labels = c("<med", ">med"))
unique(w3$GDPPPP_q)
w3$GINI_q <- ntile_na(w3$GINI,2)
unique(w3$GINI_q)
w3$GINI_q <- factor(w3$GINI_q, levels = 1:2, labels = c("<med", ">med"))
unique(w3$GINI_q)
w3 <- w3 %>% mutate(libD_q = ntile(LibD, 2))
unique(w3$libD_q)
w3$libD_q <- factor(w3$libD_q, levels = 1:2, labels = c("<med", ">med"))
unique(w3$libD_q)
w3 <- w3 %>% mutate(egaD_q = ntile(EgaD, 2))
unique(w3$egaD_q)
w3$egaD_q <- factor(w3$egaD_q, levels = 1:2, labels = c("<med", ">med"))
unique(w3$egaD_q)
both_waves <- bind_rows(w2,w3)
rio::export(both_waves, file = "data/00_data_prep.R_country_level_data_wQs.xlsx")