This repository was archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_create_v01_phdcn_merged.do
More file actions
220 lines (166 loc) · 8.79 KB
/
08_create_v01_phdcn_merged.do
File metadata and controls
220 lines (166 loc) · 8.79 KB
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
capture log close
capture clear all
set more off
global project_directory "D:\projects\nhood_mediation_lead"
*global project_directory "C:\Users\Geoff.Wodtke\Desktop\projects\nhood_mediation_lead"
*global project_directory "C:\nhood_mediation_lead"
log using "${project_directory}\programs\_LOGS\08_create_v01_phdcn_merged.log", replace
/*
DO-FILE NAME: 08_create_v01_phdcn_merged.do
AUTHOR: Sagi Ramaj
DATE UPDATED: 08/04/2020 (GW)
PURPOSE: merge phdcn files together and then with bldb and ncdb
NOTES:
*/
//Merging PHDCN files
use "${project_directory}\data\phdcn\v01_phdcn_demo.dta", clear
merge 1:1 nSUBID using "${project_directory}\data\phdcn\v01_phdcn_header.dta", nogen
merge 1:1 nSUBID using "${project_directory}\data\phdcn\v01_phdcn_master.dta", nogen
merge 1:1 nSUBID using "${project_directory}\data\phdcn\v01_phdcn_ppvt.dta", nogen
save "${project_directory}\data\_TEMP\phdcn_full.dta", replace
//Merging blood lead tests
use "${project_directory}\data\cdph_bldb\v01_bldb_nc.dta", clear
keep nyear nlinknc navgbllsm nprbllgt5sm nobs
keep if nyear >= 1994 & nyear <=1997
reshape wide navgbllsm nprbllgt5sm nobs, i(nlinknc) j(nyear)
rename nlinknc nlinknc_1
merge m:m nlinknc_1 using "${project_directory}\data\_TEMP\phdcn_full.dta", nogen keepusing(*_1 nSUBID nCohort nstrata)
drop if nSUBID == .
gen nBL5_1 = .
replace nBL5_1 = nprbllgt5sm1995 if nPCYearInterview_1 == 1995 | nPCYearInterview_1 == 1994
replace nBL5_1 = nprbllgt5sm1996 if nPCYearInterview_1 == 1996 | nPCYearInterview_1 == .
replace nBL5_1 = nprbllgt5sm1997 if nPCYearInterview_1 == 1997
gen nBLAVG_1 = .
replace nBLAVG_1 = navgbllsm1995 if nPCYearInterview_1 == 1995 | nPCYearInterview_1 == 1994
replace nBLAVG_1 = navgbllsm1996 if nPCYearInterview_1 == 1996 | nPCYearInterview_1 == .
replace nBLAVG_1 = navgbllsm1997 if nPCYearInterview_1 == 1997
gen nBLAVGlog_1 = ln(nBLAVG_1)
drop navgbllsm* nprbllgt5sm*
save "${project_directory}\data\_TEMP\phdcn_bldb_w1.dta", replace
*Wave 2
use "${project_directory}\data\cdph_bldb\v01_bldb_NC.dta", clear
keep nyear nlinknc navgbllsm nprbllgt5sm nobs
keep if nyear >= 1997 & nyear <=2000
reshape wide navgbllsm nprbllgt5sm nobs, i(nlinknc) j(nyear)
rename nlinknc nlinknc_2
merge m:m nlinknc_2 using "${project_directory}\data\_TEMP\phdcn_full.dta", nogen keepusing(*_2 nSUBID nCohort nstrata)
drop if nSUBID == .
gen nBL5_2 = .
replace nBL5_2 = nprbllgt5sm1997 if nPCYearInterview_2 == 1997
replace nBL5_2 = nprbllgt5sm1998 if nPCYearInterview_2 == 1998 | nPCYearInterview_2 == .
replace nBL5_2 = nprbllgt5sm1999 if nPCYearInterview_2 == 1999
replace nBL5_2 = nprbllgt5sm2000 if nPCYearInterview_2 == 2000
gen nBLAVG_2 = .
replace nBLAVG_2 = navgbllsm1997 if nPCYearInterview_2 == 1997
replace nBLAVG_2 = navgbllsm1998 if nPCYearInterview_2 == 1998 | nPCYearInterview_2 == .
replace nBLAVG_2 = navgbllsm1999 if nPCYearInterview_2 == 1999
replace nBLAVG_2 = navgbllsm2000 if nPCYearInterview_2 == 2000
gen nBLAVGlog_2 = ln(nBLAVG_2)
drop navgbllsm* nprbllgt5sm*
save "${project_directory}\data\_TEMP\phdcn_bldb_w2.dta", replace
*Wave 3
use "${project_directory}\data\cdph_bldb\v01_bldb_nc.dta", clear
keep nyear nlinknc navgbllsm nprbllgt5sm nobs
keep if nyear >= 2000 & nyear <=2002
reshape wide navgbllsm nprbllgt5sm nobs, i(nlinknc) j(nyear)
rename nlinknc nlinknc_3
merge m:m nlinknc_3 using "${project_directory}\data\_TEMP\phdcn_full.dta", nogen keepusing(*_3 nSUBID nCohort nstrata)
drop if nSUBID == .
gen nBL5_3 = .
replace nBL5_3 = nprbllgt5sm2000 if nPCYearInterview_3 == 2000
replace nBL5_3 = nprbllgt5sm2001 if nPCYearInterview_3 == 2001 | nPCYearInterview_3 == .
replace nBL5_3 = nprbllgt5sm2002 if nPCYearInterview_3 == 2002
gen nBLAVG_3 = .
replace nBLAVG_3 = navgbllsm2000 if nPCYearInterview_3 == 2000
replace nBLAVG_3 = navgbllsm2001 if nPCYearInterview_3 == 2001 | nPCYearInterview_3 == .
replace nBLAVG_3 = navgbllsm2002 if nPCYearInterview_3 == 2002
gen nBLAVGlog_3 = ln(nBLAVG_3)
drop navgbllsm* nprbllgt5sm*
save "${project_directory}\data\_TEMP\phdcn_bldb_w3.dta", replace
*Merging the 3 waves
use "${project_directory}\data\_TEMP\phdcn_bldb_w1.dta", clear
merge 1:1 nSUBID using "${project_directory}\data\_TEMP\phdcn_bldb_w2.dta", nogen
merge 1:1 nSUBID using "${project_directory}\data\_TEMP\phdcn_bldb_w3.dta", nogen
save "${project_directory}\data\_TEMP\phdcn_bldb.dta", replace
//Adding NCDB
*Wave 1
use "${project_directory}\data\ncdb2000\v01_ncdb_nc.dta", clear
keep nlinknc nyear ncondadvg npovertyp
keep if nyear >= 1994 & nyear <=1997
reshape wide ncondadvg npovertyp, i(nlinknc) j(nyear)
rename nlinknc nlinknc_1
merge m:m nlinknc_1 using "${project_directory}\data\_TEMP\phdcn_bldb.dta", nogen keepusing(*_1 nSUBID nCohort nstrata)
drop if nSUBID == .
gen ncondadvg_1 = .
replace ncondadvg_1 = ncondadvg1994 if nPCYearInterview_1 == 1994
replace ncondadvg_1 = ncondadvg1995 if nPCYearInterview_1 == 1995
replace ncondadvg_1 = ncondadvg1996 if nPCYearInterview_1 == 1996 | nPCYearInterview_1 == .
replace ncondadvg_1 = ncondadvg1997 if nPCYearInterview_1 == 1997
gen npovertyp_1 = .
replace npovertyp_1 = npovertyp1994 if nPCYearInterview_1 == 1994
replace npovertyp_1 = npovertyp1995 if nPCYearInterview_1 == 1995
replace npovertyp_1 = npovertyp1996 if nPCYearInterview_1 == 1996 | nPCYearInterview_1 == .
replace npovertyp_1 = npovertyp1997 if nPCYearInterview_1 == 1997
drop ncondadvg1* npovertyp1*
save "${project_directory}\data\_TEMP\full_w1.dta", replace
*Wave 2
use "${project_directory}\data\ncdb2000\v01_ncdb_nc.dta", clear
keep nlinknc nyear ncondadvg npovertyp
keep if nyear >= 1997 & nyear <=2000
reshape wide ncondadvg npovertyp, i(nlinknc) j(nyear)
rename nlinknc nlinknc_2
merge m:m nlinknc_2 using "${project_directory}\data\_TEMP\phdcn_bldb.dta", nogen keepusing(*_2 nSUBID nCohort nstrata)
drop if nSUBID == .
gen ncondadvg_2 = .
replace ncondadvg_2 = ncondadvg1997 if nPCYearInterview_2 == 1997
replace ncondadvg_2 = ncondadvg1998 if nPCYearInterview_2 == 1998 | nPCYearInterview_2 == .
replace ncondadvg_2 = ncondadvg1999 if nPCYearInterview_2 == 1999
replace ncondadvg_2 = ncondadvg2000 if nPCYearInterview_2 == 2000
gen npovertyp_2 = .
replace npovertyp_2 = npovertyp1997 if nPCYearInterview_2 == 1997
replace npovertyp_2 = npovertyp1998 if nPCYearInterview_2 == 1998 | nPCYearInterview_2 == .
replace npovertyp_2 = npovertyp1999 if nPCYearInterview_2 == 1999
replace npovertyp_2 = npovertyp2000 if nPCYearInterview_2 == 2000
drop ncondadvg1* npovertyp1* ncondadvg2* npovertyp2*
save "${project_directory}\data\_TEMP\full_w2.dta", replace
*Wave 3
use "${project_directory}\data\ncdb2000\v01_ncdb_nc.dta", clear
keep nlinknc nyear ncondadvg npovertyp
keep if nyear == 2000
reshape wide ncondadvg npovertyp, i(nlinknc) j(nyear)
rename nlinknc nlinknc_3
merge m:m nlinknc_3 using "${project_directory}\data\_TEMP\phdcn_bldb.dta", nogen keepusing(*_3 nSUBID nCohort nstrata)
drop if nSUBID == .
gen ncondadvg_3 = .
replace ncondadvg_3 = ncondadvg2000 if nPCYearInterview_3 == 2000
replace ncondadvg_3 = ncondadvg2000 if nPCYearInterview_3 == 2001 | nPCYearInterview_3 == .
replace ncondadvg_3 = ncondadvg2000 if nPCYearInterview_3 == 2002
gen npovertyp_3 = .
replace npovertyp_3 = npovertyp2000 if nPCYearInterview_3 == 2000
replace npovertyp_3 = npovertyp2000 if nPCYearInterview_3 == 2001 | nPCYearInterview_3 == .
replace npovertyp_3 = npovertyp2000 if nPCYearInterview_3 == 2002
drop ncondadvg2* npovertyp2*
save "${project_directory}\data\_TEMP\full_w3.dta", replace
*Merging 3 waves
use "${project_directory}\data\_TEMP\full_w1.dta", clear
merge 1:1 nSUBID using "${project_directory}\data\_TEMP\full_w2.dta", nogen
merge 1:1 nSUBID using "${project_directory}\data\_TEMP\full_w3.dta", nogen
gen nlnSalary_1 = ln(nSalary_1+1)
gen nlnSalary_2 = ln(nSalary_2+1)
gen nlnSalary_3 = ln(nSalary_3+1)
recode nPCMarstat_1 (1=1 married) (2 3 = 0 unmarried), gen(nPCMarried_1)
recode nPCMarstat_2 (1=1 married) (2 3 = 0 unmarried), gen(nPCMarried_2)
recode nPCMarstat_3 (1=1 married) (2 3 = 0 unmarried), gen(nPCMarried_3)
recode nPCLanguage_1 (1=1 english) (2 3 = 0 other), gen(nPCEnglish_1)
recode nPCLanguage_2 (1=1 english) (2 3 = 0 other), gen(nPCEnglish_2)
recode nPCLanguage_3 (1=1 english) (2 3 = 0 other), gen(nPCEnglish_3)
save "${project_directory}\data\v01_phdcn_merged.dta", replace
erase "${project_directory}\data\_TEMP\phdcn_bldb_w1.dta"
erase "${project_directory}\data\_TEMP\phdcn_bldb_w2.dta"
erase "${project_directory}\data\_TEMP\phdcn_bldb_w3.dta"
erase "${project_directory}\data\_TEMP\phdcn_bldb.dta"
erase "${project_directory}\data\_TEMP\full_w1.dta"
erase "${project_directory}\data\_TEMP\full_w2.dta"
erase "${project_directory}\data\_TEMP\full_w3.dta"
erase "${project_directory}\data\_TEMP\phdcn_full.dta"
log close