-
Notifications
You must be signed in to change notification settings - Fork 0
/
Variables.Rmd
534 lines (372 loc) · 10.8 KB
/
Variables.Rmd
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
---
title: "Variables"
author: "Bryon Langford, Matthew Hoctor"
date: "7/12/2021"
output:
html_document:
number_sections: no
theme: lumen
toc: yes
toc_float:
collapsed: yes
smooth_scroll: no
pdf_document:
toc: yes
word_document:
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
if (Sys.info()["sysname"] == "Windows")
knitr::opts_chunk$set(engine.path = list(stata = "C:/Program Files/Stata17/StataBE-64"))
if ((Sys.info()["sysname"] == "Darwin"))
knitr::opts_chunk$set(engine.path = list(stata = "/Applications/Stata/StataIC"))
```
```{r libraries, include=FALSE}
library(Statamarkdown)
```
# BP categories
## Median SBP
```{stata create median SBP}
use "data\NHANES0518.dta", clear
egen NmissSBP = rowmiss(bpxsy1 bpxsy2 bpxsy3 bpxsy4)
egen MaxSBP = rowmax(bpxsy1 bpxsy2 bpxsy3 bpxsy4)
egen MedSBP = rowmedian(bpxsy1 bpxsy2 bpxsy3 bpxsy4)
replace MedSBP=. if NmissSBP>2
replace MedSBP=. if NmissSBP==2 & MedSBP!=MaxSBP
save "data\NHANES0518_new.dta",replace
```
```{stata exploring missing SBP values}
use "data\NHANES0518.dta", clear
gen miss_SBP1=missing(bpxsy1)
gen miss_SBP2=missing(bpxsy2)
gen miss_SBP3=missing(bpxsy3)
gen miss_SBP4=missing(bpxsy4)
ta miss_SBP1 miss_SBP2
ta miss_SBP3 miss_SBP4
egen NmissSBP = rowmiss(bpxsy1 bpxsy2 bpxsy3 bpxsy4)
ta NmissSBP miss_SBP1
#save "data\NHANES0518_new.dta",replace
```
## Median DBP
```{stata create median DBP}
use "data\NHANES0518_new.dta", clear
egen NmissDBP = rowmiss(bpxdi1 bpxdi2 bpxdi3 bpxdi4)
egen MaxDBP = rowmax(bpxdi1 bpxdi2 bpxdi3 bpxdi4)
egen MedDBP = rowmedian(bpxdi1 bpxdi2 bpxdi3 bpxdi4)
replace MedDBP=. if NmissDBP>2
replace MedDBP=. if NmissDBP==2 & MedDBP!=MaxDBP
save "data\NHANES0518_new.dta",replace
```
```{stata exploring missing DBP values}
use "data\NHANES0518.dta", clear
gen miss_DBP1=missing(bpxdi1)
gen miss_DBP2=missing(bpxdi2)
gen miss_DBP3=missing(bpxdi3)
gen miss_DBP4=missing(bpxdi4)
ta miss_DBP1 miss_DBP2
ta miss_DBP3 miss_DBP4
egen NmissDBP = rowmiss(bpxdi1 bpxdi2 bpxdi3 bpxdi4)
ta NmissDBP miss_DBP1
egen NmissSBP = rowmiss(bpxsy1 bpxsy2 bpxsy3 bpxsy4)
ta NmissSBP NmissDBP
#save "data\NHANES0518_new.dta",replace
```
## BP Categories
```{stata BP categories}
use "data\NHANES0518_new.dta", clear
gen BP_cat=0
# replace BP_cat=0 if MedSBP<120 & MedDBP<80
replace BP_cat=1 if MedSBP>=120
replace BP_cat=2 if MedSBP>=130 | MedDBP>=80
replace BP_cat=3 if MedSBP>=140 | MedDBP>=90
replace BP_cat=. if MedSBP==. | MedDBP==.
ta BP_cat
label define BP_cat 0 "Normal" 1 "Elevated" 2 "Stage 1 HTN" 3 "Stage 2 HTN"
label values BP_cat BP_cat
label variable BP_cat "BP Category"
ta BP_cat,m
save,replace
```
## Generate Missing BP Variable
```{stata}
use "data\NHANES0518_new.dta", clear
gen BP_miss=0
replace BP_miss=1 if BP_cat==.
label define BP_miss 0 "Not Missing BP" 1 "Missing BP"
label values BP_miss BP_miss
label variable BP_miss "Meets BP Inclusion Criteria"
ta BP_miss,m
save,replace
```
## Elevated BP
```{stata}
use "data\NHANES0518_new.dta", clear
recode BP_cat 0=0 1=1 2=1 3=1 .=., gen(BP_abn)
label define BP_abn 0 "Normal BP" 1 "Abnormal BP"
label values BP_abn BP_abn
label variable BP_abn "Abnormal/Normal BP"
ta BP_cat BP_abn,m
save,replace
```
# Cannabis Use Categories
## MJ Use Categories
```{stata exploring data}
use "data\NHANES0518_new.dta", clear
ta duq200
ta duq220q
ta duq220u
```
```{stata MJ categories}
use "data\NHANES0518_new.dta", clear
recode duq200 2=0 1=1 7=. 9=., gen(MJ_cat)
replace MJ_cat=2 if duq230<77
label define MJ_cat 0 "Never Use" 1 "Past Use" 2 "Current Use"
label values MJ_cat MJ_cat
label variable MJ_cat "Cannabis Use Category"
ta MJ_cat,m
ta MJ_cat duq200,m
save,replace
```
## MJ Frequency Categories
```{stata MJ Frequency Categories}
use "data\NHANES0518_new.dta", clear
recode duq230 min/10=0 11/20=1 21/30=2 31/max=., gen(MJ_freq)
label define MJ_freq 0 "1-10 days" 1 "11-20 days" 2 "21-30 days"
label values MJ_freq MJ_freq
label variable MJ_freq "Cannabis Use Frequency In the Past 30 Days"
ta MJ_freq,m
ta MJ_freq duq200,m
save,replace
```
## Generate Single MJ Exposure Variable
```{stata unitary MJ variable}
use "data\NHANES0518_new.dta", clear
gen MJ=MJ_cat
replace MJ=3 if MJ_freq==1
replace MJ=4 if MJ_freq==2
label define MJ 0 "Never Use" 1 "Past Use" 2 "1-10 times in past 30 days" 3 "11-20 times in past 30 days" 4 "21-30 times in past 30 days"
label values MJ MJ
label variable MJ "Cannabis Use"
ta MJ_cat MJ_freq,m
ta MJ,m
ta MJ_freq MJ,m
save,replace
```
## Generate Missing MJ Variable
```{stata}
use "data\NHANES0518_new.dta", clear
gen MJ_miss=0
replace MJ_miss=1 if MJ_cat==.
label define MJ_miss 0 "Not Missing MJ" 1 "Missing MJ"
label values MJ_miss MJ_miss
label variable MJ_miss "Meets MJ Inclusion Criteria"
ta MJ_miss,m
ta MJ_miss BP_miss,m
save,replace
```
## Collapsed MJ variable
```{stata collapsed MJ variable}
use "data\NHANES0518_new.dta", clear
recode MJ 0=0 1=0 2=1 3=1 4=2 .=., gen(MJ2)
label define MJ2 0 "Never/Past Use" 1 "Light-Moderate 1-20 times in past 30 days" 2 "Frequent 21-30 times in past 30 days"
label values MJ2 MJ2
label variable MJ2 "Cannabis Use Collapsed"
ta MJ MJ2,m
save,replace
```
# Inclusion criteria
## MEC Examined
```{stata}
use "data\NHANES0518_new.dta", clear
gen MEC_response=1
replace MEC_response=0 if wtmec2yr==0
label define MEC_response 0 "Did not respond" 1 "Responded"
label values MEC_response MEC_response
label variable MEC_response "MEC Response"
ta MEC_response,m
ta MEC_response BP_miss,m
ta MEC_response MJ_miss,m
save,replace
```
## Age Inclusion Criteria, 20-59 Years
```{stata}
use "data\NHANES0518_new.dta", clear
recode ridageyr min/19=1 20/59=0 60/85=1 86/max=., gen(AGE_exclude)
label define AGE_exclude 0 "Age 20-59" 1 "Age Excluded"
label values AGE_exclude AGE_exclude
label variable AGE_exclude "Meets Age Inclusion Criteria"
ta AGE_exclude,m
ta AGE_exclude BP_miss,m
ta AGE_exclude MJ_miss,m
save,replace
```
## Overall Inclusion, Age, BP, MJ
```{stata}
use "data\NHANES0518_new.dta", clear
gen include=0
replace include=1 if BP_miss==0 & MJ_miss==0 & AGE_exclude==0
label define include 0 "Excluded" 1 "Included"
label values include include
label variable include "Meets Overall Inclusion Criteria"
ta include,m
ta include BP_miss,m
ta include MJ_miss,m
ta include AGE_exclude,m
save,replace
```
# Covariate Coding
## Race/Ethnicity
```{stata}
use "data\NHANES0518_new.dta", clear
#ta ridreth1
recode ridreth1 1=3 2=4 3=1 4=2 5=4, gen(race_eth)
label define race_eth 1 "White-NH" 2 "Black_NH" 3 "Mex Am" 4 "Oth"
label values race_eth race_eth
label variable race_eth "Recoded Race & Ethnicity"
ta race_eth
ta ridreth1 race_eth,m
save,replace
```
## Smoking
```{stata}
use "data\NHANES0518_new.dta", clear
recode smd650 min/10=2 11/20=3 21/95=4 96/max=., gen(SMK_cat)
replace SMK_cat=1 if smq040==3
replace SMK_cat=0 if smq020==2
label define SMK_cat 0 "Never" 1 "Past Smoker" 2 "Light, 1-10 cif/day" 3 "Moderate, 11-20 cig/day" 4 "Heavy, 21+ cig/day"
label values SMK_cat SMK_cat
label variable SMK_cat "Smoking Category"
ta SMK_cat,m
# ta SMK_cat smd650,m
# ta SMK_cat BP_miss,m
# ta SMK_cat MJ_miss,m
save,replace
```
## Gender
```{stata}
use "data\NHANES0518_new.dta", clear
recode riagendr 2=0 1=1, gen(gndr)
label define gndr 0 "Female" 1 "Male"
label values gndr gndr
label variable gndr "Gender"
ta gndr,m
# ta gndr riagendr,m
save,replace
```
## Alcohol
```{stata}
use "data\NHANES0518_new.dta", clear
recode alq130 min/2=0 3/4=1 5/95=2 99/max=., gen(AL_cat)
replace AL_cat=0 if alq101==2 | alq111==2 | alq121==0
replace AL_cat=1 if alq130==2 & riagendr==2
replace AL_cat=2 if alq130==4 & riagendr==2
label define AL_cat 0 "None-Light" 1 "Moderate" 2 "Heavy"
label values AL_cat AL_cat
label variable AL_cat "Alcohol Use Category"
ta AL_cat,m
# ta AL_cat BP_miss,m
# ta AL_cat MJ_miss,m
save,replace
```
## Healthy Eating Index
```{stata}
use "data\NHANES0518_new.dta", clear
gen hei2015=hei2015_total_score
replace hei2015=. if dr1tkcal==. & dr2tkcal==.
replace hei2015=. if dr1tkcal<500 & dr1tkcal!=.
replace hei2015=. if dr1tkcal>5000 & dr1tkcal!=.
replace hei2015=. if dr2tkcal<500 & dr2tkcal!=.
replace hei2015=. if dr2tkcal>5000 & dr2tkcal!=.
# replace hei2015_total_score=. if dr1tkcal<500
# replace hei2015_total_score=. if dr1tkcal>5000
# replace hei2015_total_score=. if dr2tkcal<500
# replace hei2015_total_score=. if dr2tkcal>5000
label variable hei2015 "Healthy Eating Index"
gen HEI_miss=0
replace HEI_miss=1 if hei2015==.
ta include HEI_miss
save,replace
```
## Education Category
```{stata}
use "data\NHANES0518_new.dta", clear
recode dmdeduc2 1=1 2=2 3=3 4=4 5=5 7=. 9=., gen(EDUC_cat)
label define EDUC_cat 1 "Less than 9th Grade" 2 "Less than High School" 3 "High School/GED" 4 "Some College" 5 "College Graduate"
label values EDUC_cat EDUC_cat
label variable EDUC_cat "Recode Education Level"
ta dmdeduc2 EDUC_cat,m
save,replace
```
## Survey Year
```{stata}
use "data\NHANES0518_new.dta", clear
label define sddsrvyr 4 "2005-2006" 5 "2007-2008" 6 "2009-2010" 7 "2011-2012" 8 "2013-2014" 9 "2015-2016" 10 "2017-2018"
label values sddsrvyr sddsrvyr
label variable sddsrvyr "Survey Year"
ta sddsrvyr,m
save,replace
```
## BMI implausible values
```{stata}
use "data\NHANES0518_new.dta", clear
gen BMI_miss=0
replace BMI_miss=1 if bmxbmi==.
ta BMI_miss include,m
replace bmxbmi=. if bmxbmi>65
replace BMI_miss=1 if bmxbmi==.
ta BMI_miss include,m
save,replace
```
## MEC weight
```{stata}
use "data\NHANES0518_new.dta", clear
gen wtmec12yr = (1/7) * wtmec2yr
save,replace
```
# Cross tabulation of missing variables for T1
```{stata}
use "data\NHANES0518_new.dta", clear
ta EDUC_cat include,m
ta gndr include,m
ta SMK_cat include,m
ta AL_cat include,m
gen AGE_miss =0
replace AGE_miss=1 if ridageyr==.
ta AGE_miss include,m
# gen BMI_miss=0
# replace BMI_miss=1 if bmxbmi==.
ta BMI_miss include,m
gen PIR_miss=0
replace PIR_miss=1 if indfmpir==.
ta PIR_miss include,m
# gen HEI_miss=0
# replace HEI_miss=1 if hei2015==.
ta HEI_miss include,m
```
# Cross tabulation of missing variables for T1, by MJ_cat
```{stata}
use "data\NHANES0518_new.dta", clear
svyset sdmvpsu [pw=wtmec12yr], strata(sdmvstra)
ta EDUC_cat MJ_cat if include==1,m
ta gndr MJ_cat if include==1,m
ta SMK_cat MJ_cat if include==1,m
ta AL_cat MJ_cat if include==1,m
gen AGE_miss =0
replace AGE_miss=1 if ridageyr==.
ta AGE_miss MJ_cat if include==1,m
# gen BMI_miss=0
# replace BMI_miss=1 if bmxbmi==.
ta BMI_miss MJ_cat if include==1,m
gen PIR_miss=0
replace PIR_miss=1 if indfmpir==.
ta PIR_miss MJ_cat if include==1,m
# gen HEI_miss=0
# replace HEI_miss=1 if hei2015_total_score==.
ta HEI_miss MJ_cat if include==1,m
svy, subpop(if include==1): ta HEI_miss MJ_cat, col percent
```
# Create .zip file for github upload
```{r}
zip("data/NHANES0518_new.zip","data/NHANES0518_new.dta")
```