-
Notifications
You must be signed in to change notification settings - Fork 1
/
04_combine_dataset_momlevel.do
220 lines (145 loc) · 4.94 KB
/
04_combine_dataset_momlevel.do
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PROJECT: CPI - CHDN Nutrition Security Report
PURPOSE: Combined all mothers Dataset
AUTHOR: Nicholus
CREATED: 02 Dec 2019
MODIFIED:
THINGS TO DO:
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
** PREPARE DATASETS FOR COMBINATION **
local org vi chdn
foreach x in `org' {
// Main respondent dataset //
use "$dta/hh_baseline_mcct_`x'.dta", clear
gen key = _index
order key, before(_index)
drop _index
save "$dta/respondent_`x'.dta",replace
clear
// hh members dataset //
use "$dta/hh_consent_hh_grp_grp_hh_`x'.dta", clear
gen key = _parent_index
order key, before(_parent_index)
gen hh_mem_key = _parent_index + "_" + test
order hh_mem_key, after(key)
drop _index _parent_index
save "$dta/hh_roster_`x'", replace
clear
// mom related data from main baseline survey //
// mom health dataset //
use "$dta/hh_consent_ancpast_rep_`x'.dta", clear
gen key = _parent_index
order key, before(_parent_index)
drop if mi(women_id_pregpast)
gen hh_mem_key = _parent_index + "_" + women_id_pregpast
order hh_mem_key, after(key)
drop _index _parent_index
save "$dta/mom_health_`x'", replace
clear
// mom related data from anthro dataset //
// anthro respondent //
use "$dta/anthro_mcct_anthro_`x'.dta", clear
gen key = _index
order key, before(_index)
drop _index
save "$dta/anthro_respondent_`x'.dta",replace
clear
// anthro mother info //
use "$dta/anthro_consent_hh_grp_grp_family_`x'.dta", clear
gen key = _parent_index
order key, before(_parent_index)
gen mom_key = _parent_index + "_" + testfamily
order mom_key, after(key)
drop _index _parent_index
save "$dta/anthro_hh_mom_roster_`x'", replace
clear
// mom anthro data //
use "$dta/anthro_consent_mom_anthro_rep_`x'.dta", clear
gen key = _parent_index
order key, before(_parent_index)
gen mom_key = _parent_index + "_" + calc_mom_post
order mom_key, after(key)
drop _index _parent_index
save "$dta/mom_anthro_muac_`x'", replace
clear
}
********************************************************************************
********************************************************************************
** COMBINED DATASET AT ORGANIZATION LEVEL **
local org vi chdn
foreach x in `org' {
// non - anthro child level data - iycf and health information //
use "$cdta/respondent_cleanded_`x'.dta",clear
tostring key, replace
tostring _id _parent_table_name _tags _notes _version _duration _xform_id, replace
merge 1:m key using "$dta/hh_roster_`x'.dta"
keep if _merge == 3
drop _merge
order hh_mem_key test, after(key)
merge 1:m hh_mem_key using "$dta/mom_health_`x'.dta"
keep if _merge == 3
drop _merge
order hh_mem_key test women_id_pregpast, after(key)
save "$dta/mom_health_combined_`x'.dta", replace
clear
}
// anthro mom level data //
local org vi chdn
foreach x in `org' {
use "$cdta/anthro_respondent_cleanded_`x'.dta", clear
merge 1:m key using "$dta/anthro_hh_mom_roster_`x'.dta"
keep if _merge == 3
drop _merge
order test, after(key)
merge m:1 mom_key using "$dta/mom_anthro_muac_`x'.dta"
keep if _merge == 3
drop _merge
order test mom_key, after(key)
save "$dta/mom_anthro_muac_combined_`x'.dta", replace
clear
}
********************************************************************************
********************************************************************************
** PREPARE TO COMBINE AS ONE CHILD DATASET **
// non - anthro dataset //
use "$dta/mom_health_combined_vi.dta", clear
append using "$dta/mom_health_combined_chdn.dta"
save "$dta/mom_health_combined.dta", replace
clear
/*
// anthro dataset //
use "$dta/mom_anthro_muac_combined_vi.dta", clear
append using "$dta/mom_anthro_muac_combined_chdn.dta"
save "$dta/mom_anthro_muac_combined.dta", replace
clear
*/
// anthro dataset //
use "$dta/mom_anthro_muac_combined_vi.dta", clear
merge m:m cal_respid using "$cdta/respondent_cleanded_vi.dta", ///
keepusing(wealth_quintile wealth_poorest wealth_poor wealth_medium wealth_wealthy wealth_wealthiest)
drop if _merge == 2
local wealth wealth_quintile wealth_poorest wealth_poor wealth_medium wealth_wealthy wealth_wealthiest
foreach var in `wealth' {
replace `var' = .n if _merge == 1
}
drop _merge
tempfile vi
save `vi', replace
clear
use "$dta/mom_anthro_muac_combined_chdn.dta", clear
merge m:m cal_respid using "$cdta/respondent_cleanded_chdn.dta", ///
keepusing(wealth_quintile wealth_poorest wealth_poor wealth_medium wealth_wealthy wealth_wealthiest)
drop if _merge == 2
local wealth wealth_quintile wealth_poorest wealth_poor wealth_medium wealth_wealthy wealth_wealthiest
foreach var in `wealth' {
replace `var' = .n if _merge == 1
}
drop _merge
tempfile chdn
save `chdn', replace
clear
use `vi', clear
append using "`chdn'", gen(source)
save "$dta/mom_anthro_muac_combined.dta", replace
clear