-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_data_reading.R
180 lines (121 loc) · 5.08 KB
/
1_data_reading.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
##### Dissertation Maria Reyes Retana
# This code reads the raw data base from the Mexican Family Life Survey which can be found here:
# http://www.ennvih-mxfls.org/english/ennvih-1.html
##### Libraries #####
library(tidyverse)
library(foreign)
library(haven)
library(purrr)
# Read data from different waves
##### 2002 #####
# select all the variables we need from each book
# Book control
names <- c("c_portad", "c_ls", "hh02w_bc", "c_conpor")
for(i in names){
filepath <- file.path("Data/2002/hh02dta_bc", paste(i,".dta",sep=""))
assign(paste(i,"_02", sep = ""), read_dta(filepath))
}
# Book IIIA - Characteristics of adult household members
names <- c("iiia_dh", "iiia_ed", "iiia_tb", "hh02w_b3a", "iiia_ata")
for(i in names){
filepath <- file.path("Data/2002/hh02dta_b3a", paste(i,".dta",sep=""))
assign(paste(i,"_02", sep = ""), read_dta(filepath))
}
# Book V - Characteristics of Children younger than 15 years old
names <- c("v_portad", "v_edna", "hh02w_b5", "v_conpor", "v_esn")
for(i in names){
filepath <- file.path("Data/2002/hh02dta_b5", paste(i,".dta",sep=""))
assign(paste(i,"_02", sep = ""), read_dta(filepath))
}
# Book S - anthropometrics and biomarkers
names <- c("s_portad", "s_sa", "hh02w_bs")
for(i in names){
filepath <- file.path("Data/2002/hh02dta_bs", paste(i,".dta",sep=""))
assign(paste(i,"_02", sep = ""), read_dta(filepath))
}
# Book EA - Adult cognitive ability
names <- c("ea_portad", "ea_eca", "hh02w_bea")
for(i in names){
filepath <- file.path("Data/2002/hh02dta_bea", paste(i,".dta",sep=""))
assign(paste(i,"_02", sep = ""), read_dta(filepath))
}
# Book EN - Child cognitive ability
names <- c("en_portad", "en_ecn", "hh02w_ben")
for(i in names){
filepath <- file.path("Data/2002/hh02dta_ben", paste(i,".dta",sep=""))
assign(paste(i,"_02", sep = ""), read_dta(filepath))
}
##### 2005 ####
# Book control
names <- c("c_portad", "c_ls", "hh05w_bc", "hh05w_bcl", "c_conpor")
for(i in names){
filepath <- file.path("Data/2005/hh05dta_bc", paste(i,".dta",sep=""))
assign(paste(i,"_05", sep = ""), read_dta(filepath))
}
# Book IIIA - Characteristics of adult household members
names <- c("iiia_dh", "iiia_ed", "iiia_tb", "ehh05w_b3a", "ehh05w_b3al", "iiia_ata")
for(i in names){
filepath <- file.path("Data/2005/hh05dta_b3a", paste(i,".dta",sep=""))
assign(paste(i,"_05", sep = ""), read_dta(filepath))
}
# Book V - Characteristics of Children younger than 15 years old
names <- c("v_portad", "v_edna", "ehh05w_b5", "ehh05w_b5l", "v_conpor", "v_esn")
for(i in names){
filepath <- file.path("Data/2005/hh05dta_b5", paste(i,".dta",sep=""))
assign(paste(i,"_05", sep = ""), read_dta(filepath))
}
# Book S - anthropometrics and biomarkers
names <- c("s_portad", "s_sa", "ehh05w_bs", "ehh05w_bsl")
for(i in names){
filepath <- file.path("Data/2005/hh05dta_bs", paste(i,".dta",sep=""))
assign(paste(i,"_05", sep = ""), read_dta(filepath))
}
# Book EA - Adult cognitive ability
names <- c("ea_portad", "ea_eca", "ehh05w_bea", "ehh05w_beal")
for(i in names){
filepath <- file.path("Data/2005/hh05dta_bea", paste(i,".dta",sep=""))
assign(paste(i,"_05", sep = ""), read_dta(filepath))
}
# Book EN - Child cognitive ability
names <- c("en_portad", "en_ecn", "ehh05w_ben", "ehh05w_benl")
for(i in names){
filepath <- file.path("Data/2005/hh05dta_ben", paste(i,".dta",sep=""))
assign(paste(i,"_05", sep = ""), read_dta(filepath))
}
##### 2009 ####
# Book control
names <- c("c_portad", "c_ls", "hh09w_bc", "hh09_lw_bc", "c_conpor")
for(i in names){
filepath <- file.path("Data/2009/hh09dta_bc", paste(i,".dta",sep=""))
assign(paste(i,"_09", sep = ""), read_dta(filepath))
}
# Book IIIA - Characteristics of adult household members
names <- c("iiia_dh", "iiia_ed", "iiia_tb", "hh09w_b3a", "hh09_lw_b3a", "iiia_ata")
for(i in names){
filepath <- file.path("Data/2009/hh09dta_b3a", paste(i,".dta",sep=""))
assign(paste(i,"_09", sep = ""), read_dta(filepath))
}
# Book V - Characteristics of Children younger than 15 years old
names <- c("v_portad", "v_edna", "hh09w_b5", "hh09_lw_b5", "v_conpor", "v_esn")
for(i in names){
filepath <- file.path("Data/2009/hh09dta_b5", paste(i,".dta",sep=""))
assign(paste(i,"_09", sep = ""), read_dta(filepath))
}
# Book S - anthropometrics and biomarkers
names <- c("s_portad", "s_sa", "hh09w_bs", "hh09_lw_bs")
for(i in names){
filepath <- file.path("Data/2009/hh09dta_bs", paste(i,".dta",sep=""))
assign(paste(i,"_09", sep = ""), read_dta(filepath))
}
# Book EA - Adult cognitive ability
names <- c("ea_portad", "ea_eca", "hh09w_bea", "hh09_lw_bea")
for(i in names){
filepath <- file.path("Data/2009/hh09dta_bea", paste(i,".dta",sep=""))
assign(paste(i,"_09", sep = ""), read_dta(filepath))
}
# Book EN - Child cognitive ability
names <- c("en_portad", "en_ecn", "hh09w_ben", "hh09_lw_ben")
for(i in names){
filepath <- file.path("Data/2009/hh09dta_ben", paste(i,".dta",sep=""))
assign(paste(i,"_09", sep = ""), read_dta(filepath))
}