-
Notifications
You must be signed in to change notification settings - Fork 0
/
Load_and_reappend_datasets.txt
467 lines (388 loc) · 25.7 KB
/
Load_and_reappend_datasets.txt
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
##Purpose: deriving and harmonising sociodemographic variables across cohorts
##Date created: 05/10/2023
##Date last modified:09/10/2023
##RT modified to remove small cell count in freq of missingness
##---------------------------------------------------------------------------------------------------------
##LOADING PACKAGES
##---------------------------------------------------------------------------------------------------------
reqPackages <- c("haven", "dplyr", "RODBC", "expss", "stringr", "expss", "sjlabelled", "labelled", "tidyr", "rstudioapi", "purrr", "tidyverse")
lapply(reqPackages, require, character.only=TRUE)
##clear working environment
rm(list=ls())
setwd("S:/LLC_0004/data/.rdata for recoding variables")
##---------------------------------------------------------------------------------------------------------
##LOADING DATA##
##---------------------------------------------------------------------------------------------------------
##USOC
load("S://LLC_0004//data//.rdata for recoding variables//USOC_all_wide_021023.rdata")
##ELSA
load("S://LLC_0004//data//.rdata for recoding variables//ELSA_wide_031023.rdata")
##ALSPAC CHILDREN
load("S://LLC_0004//data//.rdata for recoding variables/ALSPAC_children_wide_021023.rdata")
##ALSPAC MOTHERS
load("S://LLC_0004//data//.rdata for recoding variables/ALSPAC_mothers_wide_021023.rdata")
ls()
##---------------------------------------------------------------------------------------------------------
##HARMONISING VARIABLES##
##---------------------------------------------------------------------------------------------------------
##sex
##education
##shielding status
##pre-pandemic general health
##keyworker at any time during pandemic
##pre-pandemic mental health
##---------------------------------------------------------------------------------------------------------
##SEX (MALE=1; FEMALE=2)
##---------------------------------------------------------------------------------------------------------
USOC already correctly coded - xsample_sex_dv
ELSA already correctly coded - new_sex
ALSPAC CHILDREN already correctly coded - wave0_kz021
ALSPAC MOTHERS - all female, no variable available
##USOC##
look_for(ukhls_v0003, "sex_dv", details="none")##detail=none prints just the variable name and any labels containing string
table(ukhls_v0003$xsample_sex_dv, useNA="always")##this variable has only <10 missing from whole sample
##there is covid-wave sex that I could use to pick up NA's but will leave this for now as only deriving this as a
##backup to replace missingness in the admin data
##ELSA##
look_for(elsa_v0001, "sex", details="none")
table(elsa_v0001$C19_wave1_sex, useNA="always")
## 1 2 <NA>
##3060 3980 2040
table(elsa_v0001$C19_wave2_sex, useNA="always")
## 1 2 <NA>
##2966 3828 2286
table(elsa_v0001$wave9_p_sex, useNA="always")
## 1 2 <NA>
##3854 4882 344
##if sex not available at wave 9, use sex from covid surveys
elsa_v0001$new_sex <- ifelse(is.na(elsa_v0001$wave9_p_sex), elsa_v0001$C19_wave1_sex, elsa_v0001$wave9_p_sex)
elsa_v0001$new_sex <- ifelse(is.na(elsa_v0001$new_sex), elsa_v0001$C19_wave2_sex, elsa_v0001$new_sex)
table(elsa_v0001$new_sex, useNA="always")
## 1 2 <NA>
##4011 5069 0
##ALSPAC CHILDREN##
look_for(alspac_children_v0001, "sex", details="none")
table(alspac_children_v0001$wave0_kz021, useNA="always")
##this is the only sex variable
##ALSPAC MOTHERS##
look_for(alspac_mothers_v0001, "sex", details="none")
##---------------------------------------------------------------------------------------------------------
##EDUCATION (HIGHER ED=0; A-LEVEL OR EQUIV=1; GCSE OR EQUIV=2; <GCSE/NONE=3)
##---------------------------------------------------------------------------------------------------------
##USOC##
look_for(ukhls_v0003, "education", details="none")
table(ukhls_v0003$k_qfhigh_dv, useNA="always")
table(ukhls_v0003$j_qfhigh_dv, useNA="always")
str(ukhls_v0003$i_qfhigh, useNA="always")
str(ukhls_v0003$h_qfhigh, useNA="always")
##if highest qualification missing at wave k, use wave j, and so on
ukhls_v0003$edu <- ifelse(is.na(ukhls_v0003$k_qfhigh_dv), ukhls_v0003$j_qfhigh_dv, ukhls_v0003$k_qfhigh_dv)
ukhls_v0003$edu <- ifelse(is.na(ukhls_v0003$edu), ukhls_v0003$i_qfhigh_dv, ukhls_v0003$edu)
ukhls_v0003$edu <- ifelse(is.na(ukhls_v0003$edu), ukhls_v0003$h_qfhigh_dv, ukhls_v0003$edu)
ukhls_v0003$edu <- ifelse(is.na(ukhls_v0003$edu), ukhls_v0003$g_qfhigh_dv, ukhls_v0003$edu)
##recoding education variable
edu_usoc <- function(new, old, data, label){
tmp <- data
tmp[,new] <- NA
tmp[,new][tmp[,old]<0] <- NA
tmp[,new][tmp[,old]>=1 & tmp[,old]<=6] <- 0
tmp[,new][tmp[,old]>=7 & tmp[,old]<=9] <- 1
tmp[,new][tmp[,old]>=10 & tmp[,old]<=15] <- 2
tmp[,new][tmp[,old]>=16] <- 3 ##check this one
##adding labels
var_lab(tmp[,new]) = label
tmp[,new] <- add_labels(tmp[,new], labels = c("Degree or above" = 0, "A-level or equiv" = 1, "GCSE or equiv" = 2, "<GCSE or none" = 3))
return(tmp)
}
ukhls_v0003 <- edu_usoc(new="new_edu", old="edu", data=ukhls_v0003, label="Level of education")
table(ukhls_v0003$new_edu, useNA="always")
#ELSA#
look_for(elsa_v0001, "qualification", details="none")
table(elsa_v0001$C19_wave1_w9edqual, useNA="always")
table(elsa_v0001$wave9_p_edqual, useNA="always")
##If missing at covid wave, use wave 9
elsa_v0001$edu <- ifelse(is.na(elsa_v0001$C19_wave1_w9edqual), elsa_v0001$wave9_p_edqual, elsa_v0001$C19_wave1_w9edqual)
table(elsa_v0001$edu, useNA="always")
unique(elsa_v0001$C19_wave1_w9edqual)
unique(elsa_v0001$wave9_p_edqual)
##recoding education variable
edu_elsa <- function(new, old, data, label){
tmp <- data
tmp[,new] <- NA
tmp[,new][tmp[,old]<0 | tmp[,old]==6] <- NA ##have included "foreign/other" here
tmp[,new][tmp[,old]==1] <- 0
tmp[,new][tmp[,old]==2 | tmp[,old]==3] <- 1
tmp[,new][tmp[,old]==4 | tmp[,old]==5] <- 2
tmp[,new][tmp[,old]==7] <- 3
#adding labels
var_lab(tmp[,new]) = label
tmp[,new] <- add_labels(tmp[,new], labels = c("Degree or above" = 0, "A-level or equiv" = 1, "GCSE or equiv" = 2, "<GCSE or none" = 3))
return(tmp)
}
elsa_v0001 <- edu_elsa(new="new_edu", old="edu", data=elsa_v0001, label="Level of education")
table(elsa_v0001$new_edu, useNA="always")
##ALSPAC CHILDREN
look_for(alspac_children_v0001, "degree", details="none")
##doesn't seem to be qualifications/education data available for the children beyond whether they have no qualifications vs some
table(alspac_children_v0001$wave0_ypf7510, useNA="always")
##ALSPAC MOTHERS
look_for(alspac_mothers_v0001, "education", details="none")
table(alspac_mothers_v0001$wave0_c645a, useNA="always")
unique(alspac_mothers_v0001$wave0_c645a)
##recoding education variable
edu_mothers <- function(new, old, data, label){
tmp <- data
tmp[,new] <- NA
tmp[,new][tmp[,old]<0] <- NA
tmp[,new][tmp[,old]==5] <- 0
tmp[,new][tmp[,old]==4 | tmp[,old]==3] <- 1
tmp[,new][tmp[,old]<=3 & tmp[,old]>=1] <- 2
tmp[,new][tmp[,old]==0] <- 3
#adding labels
var_lab(tmp[,new]) = label
tmp[,new] <- add_labels(tmp[,new], labels = c("Degree or above" = 0, "A-level or equiv" = 1, "GCSE or equiv" = 2, "<GCSE or none" = 3))
return(tmp)
}
alspac_mothers_v0001 <- edu_mothers(new="new_edu", old="wave0_c645a", data=alspac_mothers_v0001, label="Level of education")
table(alspac_mothers_v0001$new_edu, useNA="always")
##---------------------------------------------------------------------------------------------------------
##COVID-19 SHIELDING (NOT SHIELDING = 0; SHIELDING = 1)
##---------------------------------------------------------------------------------------------------------
##USOC##
look_for(ukhls_v0003, "shield", details="none")
##ca_nhsshield (all except cf) cg_nhsshield2; ch_nhsshield3
table(ukhls_v0003$ca_nhsshield, useNA="always")
table(ukhls_v0003$cb_nhsshield, useNA="always")
table(ukhls_v0003$cc_nhsshield, useNA="always")
table(ukhls_v0003$cd_nhsshield, useNA="always")
table(ukhls_v0003$ce_nhsshield, useNA="always")
table(ukhls_v0003$cg_nhsshield2, useNA="always")
table(ukhls_v0003$ch_nhsshield3, useNA="always")
##starting with most recent data, if shielding status not available, use previous wave
##doing it this way as shielding list changed as time went on
ukhls_v0003$shield <- ifelse(is.na(ukhls_v0003$ch_nhsshield3), ukhls_v0003$cg_nhsshield2, ukhls_v0003$ch_nhsshield3)
ukhls_v0003$shield <- ifelse(is.na(ukhls_v0003$shield), ukhls_v0003$ce_nhsshield, ukhls_v0003$shield)
ukhls_v0003$shield <- ifelse(is.na(ukhls_v0003$shield), ukhls_v0003$cd_nhsshield, ukhls_v0003$shield)
ukhls_v0003$shield <- ifelse(is.na(ukhls_v0003$shield), ukhls_v0003$cc_nhsshield, ukhls_v0003$shield)
ukhls_v0003$shield <- ifelse(is.na(ukhls_v0003$shield), ukhls_v0003$cb_nhsshield, ukhls_v0003$shield)
ukhls_v0003$shield <- ifelse(is.na(ukhls_v0003$shield), ukhls_v0003$ca_nhsshield, ukhls_v0003$shield)
##recoding shielding variable
shield<- function(new, old, data, label){
tmp <- data
tmp[,new] <- NA
tmp[,new][tmp[,old]<0] <- NA
tmp[,new][tmp[,old]==2] <- 0
tmp[,new][tmp[,old]==1] <- 1
#adding labels
var_lab(tmp[,new]) = label
tmp[,new] <- add_labels(tmp[,new], labels = c("No" = 0, "Yes" = 1))
return(tmp)
}
ukhls_v0003 <- shield(new="new_shield", old="shield", data=ukhls_v0003, label="Shielding at any time during pandemic?")
table(ukhls_v0003$new_shield, useNA="always")
##ELSA##
look_for(elsa_v0001, "vulnerable", details="none")
##elsa doesn't seem to have shielding, but has "contacted by the nhs or your gp and advised that you are vulnerable and at risk"
table(elsa_v0001$C19_wave1_cvvuln, useNA="always")
##recoding missing variables to NA
elsa_v0001 <- shield(new="new_shield", old="C19_wave1_cvvuln", data=elsa_v0001, label="Shielding at any time during pandemic?")
table(elsa_v0001$new_shield, useNA="always")
##recoding missing variables to NA
##ALSPAC CHILDREN##
look_for(alspac_children_v0001, "vulnerable", details="none")
##has the following "Participant self-isolated because they are in a vulnerable group"
table(alspac_children_v0001$wave2_covid2yp_2163, useNA="always")
table(alspac_children_v0001$wave1_covid1yp_3013, useNA="always")
alspac_children_v0001$shield <- ifelse(is.na(alspac_children_v0001$wave2_covid2yp_2163), alspac_children_v0001$wave1_covid1yp_3013, alspac_children_v0001$wave2_covid2yp_2163)
table(alspac_children_v0001$shield, useNA="always")
alspac_children_v0001 <- shield(new="new_shield", old="shield", data=alspac_children_v0001, label="Shielding at any time during pandemic?")
table(alspac_children_v0001$new_shield, useNA="always")
##ALSPAC MOTHERS##
look_for(alspac_mothers_v0001, "vulnerable", details="none")
##has the following "Participant self-isolated because they are in a vulnerable group"
table(alspac_mothers_v0001$wave2_covid2m_2163, useNA="always")
table(alspac_mothers_v0001$wave1_covid1m_3013, useNA="always")
alspac_mothers_v0001$shield <- ifelse(is.na(alspac_mothers_v0001$wave2_covid2m_2163), alspac_mothers_v0001$wave1_covid1m_3013, alspac_mothers_v0001$wave2_covid2m_2163)
table(alspac_mothers_v0001$shield, useNA="always")
alspac_mothers_v0001 <- shield(new="new_shield", old="shield", data=alspac_mothers_v0001, label="Shielding at any time during pandemic?")
table(alspac_mothers_v0001$new_shield, useNA="always")
##---------------------------------------------------------------------------------------------------------
##PRE-PANDEMIC GENERAL HEALTH (1=EXCELLENT; 2=VERY GOOD; 3=GOOD; 4=FAIR, 5=POOR)
##---------------------------------------------------------------------------------------------------------
##USOC##
look_for(ukhls_v0003, "general health", details="none")
##j_scsf1 General health
unique(ukhls_v0003$j_scsf1)
##Recoding missing values to NA
ukhls_v0003$new_prehealth <- ukhls_v0003$j_scsf1
ukhls_v0003$new_prehealth[ukhls_v0003$j_scsf1<0] <- NA
table(ukhls_v0003$new_prehealth, useNA="always")
##ELSA##
look_for(elsa_v0001, "general health", details="none")
##wave9_g_hehelf Self-reported general health
unique(elsa_v0001$wave9_g_hehelf)
elsa_v0001$new_prehealth <- elsa_v0001$wave9_g_hehelf
elsa_v0001$new_prehealth[elsa_v0001$wave9_g_hehelf<0] <- NA
table(elsa_v0001$new_prehealth, useNA="always")
##ALSPAC MOTHERS##
##not available pre-pandemic
##ALSPAC_CHILDREN##
##not available pre-pandemic
##---------------------------------------------------------------------------------------------------------
##KEYWORKER STATUS (NOT KEYWORKER = 0; KEYWORKER = 1)
##---------------------------------------------------------------------------------------------------------
##USOC##
look_for(ukhls_v0003, "keyworker", details="none")
##only available at wave ca
##recoding keyworker variable
key <- function(new, old, data, label){
tmp <- data
tmp[,new] <- NA
tmp[,new][tmp[,old]<0] <- NA
tmp[,new][tmp[,old]==2] <- 0
tmp[,new][tmp[,old]==1] <- 1
#adding labels
var_lab(tmp[,new]) = label
tmp[,new] <- add_labels(tmp[,new], labels = c("No" = 0, "Yes" = 1))
return(tmp)
}
ukhls_v0003 <- key(new="new_keyworker", old="ca_keyworker", data=ukhls_v0003, label="Self-reported keyworker at any time during pandemic?")
table(ukhls_v0003$new_keyworker, useNA="always")
table(ukhls_v0003$ca_keyworker, useNA="always")
##ELSA##
look_for(elsa_v0001, "keyworker", details="none")
##C19_wave1_cvkey
table(elsa_v0001$C19_wave1_cvkey, useNA="always")
##C19_wave2_cvkey
table(elsa_v0001$C19_wave2_cvkey, useNA="always")
##recoding missing
elsa_v0001$C19_wave1_cvkey[elsa_v0001$C19_wave1_cvkey<0] <- NA
elsa_v0001$C19_wave2_cvkey[elsa_v0001$C19_wave2_cvkey<0] <- NA
##recoding so that if participant reported being keyworker AT EITHER WAVE, they are coded as key worker
elsa_v0001$new_keyworker <- NA
elsa_v0001$new_keyworker[elsa_v0001$C19_wave1_cvkey==1 | elsa_v0001$C19_wave2_cvkey==1] <- 1
elsa_v0001$new_keyworker[elsa_v0001$C19_wave1_cvkey==2 & elsa_v0001$C19_wave2_cvkey==2] <- 0
elsa_v0001$new_keyworker[elsa_v0001$C19_wave1_cvkey==2 & is.na(elsa_v0001$C19_wave2_cvkey)] <- 0
elsa_v0001$new_keyworker[is.na(elsa_v0001$C19_wave1_cvkey) & elsa_v0001$C19_wave2_cvkey==2] <- 0
table(elsa_v0001$new_keyworker, useNA="always")
##adding label
elsa_v0001$new_keyworker <- add_labels(elsa_v0001$new_keyworker, labels=c("No"=0, "Yes"=1))
table(elsa_v0001$new_keyworker, useNA="always")
##ALSPAC MOTHERS##
look_for(alspac_mothers_v0001, "keyworker", details="none")
##wave0_covid1m_5045 d12: Participant is a keyworker; as defined by the government: COVID1
##wave0_covid2m_6030 e3: Pp is a keyworker/work classified as critical to COVID-19 response: COVID2
##wave1_covid1m_5046 d12b: Participant lives with a keyworker: COVID1
##wave2_covid2m_6030 e3: Pp is a keyworker/work classified as critical to COVID-19 response: COVID2
table(alspac_mothers_v0001$wave2_covid2m_6030, useNA="always")
##recoding missing
alspac_mothers_v0001$wave0_covid1m_5045[alspac_mothers_v0001$wave0_covid1m_5045<0 | alspac_mothers_v0001$wave0_covid1m_5045==9] <- NA
alspac_mothers_v0001$wave0_covid2m_6030[alspac_mothers_v0001$wave0_covid2m_6030<0 | alspac_mothers_v0001$wave0_covid2m_6030==9] <- NA
alspac_mothers_v0001$wave1_covid1m_5046[alspac_mothers_v0001$wave1_covid1m_5046<0 | alspac_mothers_v0001$wave1_covid1m_5046==9] <- NA
alspac_mothers_v0001$wave2_covid2m_6030[alspac_mothers_v0001$wave2_covid2m_6030<0 | alspac_mothers_v0001$wave2_covid2m_6030==9] <- NA
##recoding so that if participant reported being keyworker AT ANY WAVE, they are coded as key worker
alspac_mothers_v0001$new_keyworker <- NA
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==1 | alspac_mothers_v0001$wave0_covid2m_6030==1 |
alspac_mothers_v0001$wave1_covid1m_5046==1 | alspac_mothers_v0001$wave2_covid2m_6030==1] <- 1
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & alspac_mothers_v0001$wave0_covid2m_6030==2 &
alspac_mothers_v0001$wave1_covid1m_5046==2 & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & alspac_mothers_v0001$wave0_covid2m_6030==2 &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
alspac_mothers_v0001$wave1_covid1m_5046==2 & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
alspac_mothers_v0001$wave1_covid1m_5046==2 & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & alspac_mothers_v0001$wave0_covid2m_6030==2 &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & alspac_mothers_v0001$wave0_covid2m_6030==2 &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
alspac_mothers_v0001$wave1_covid1m_5046==2 & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & alspac_mothers_v0001$wave0_covid2m_6030==2 &
alspac_mothers_v0001$wave1_covid1m_5046==2 & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
alspac_mothers_v0001$wave1_covid1m_5046==2 & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
alspac_mothers_v0001$new_keyworker[is.na(alspac_mothers_v0001$wave0_covid1m_5045) & alspac_mothers_v0001$wave0_covid2m_6030==2 &
alspac_mothers_v0001$wave1_covid1m_5046==2 & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & is.na(alspac_mothers_v0001$wave0_covid2m_6030) &
alspac_mothers_v0001$wave1_covid1m_5046==2 & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & alspac_mothers_v0001$wave0_covid2m_6030==2 &
is.na(alspac_mothers_v0001$wave1_covid1m_5046) & alspac_mothers_v0001$wave2_covid2m_6030==2] <- 0
alspac_mothers_v0001$new_keyworker[alspac_mothers_v0001$wave0_covid1m_5045==2 & alspac_mothers_v0001$wave0_covid2m_6030==2 &
alspac_mothers_v0001$wave1_covid1m_5046==2 & is.na(alspac_mothers_v0001$wave2_covid2m_6030)] <- 0
table(alspac_mothers_v0001$new_keyworker, useNA="always")
##adding label
alspac_mothers_v0001$new_keyworker <- add_labels(alspac_mothers_v0001$new_keyworker, labels=c("No"=0, "Yes"=1))
table(alspac_mothers_v0001$new_keyworker, useNA="always")
##ALSPAC_CHILDREN##
look_for(alspac_children_v0001, "keyworker", details="none")
##wave0_covid1yp_5045 d12: Participant is a keyworker; as defined by the government: COVID1
##wave0_covid2yp_6030 e3: Pp is a keyworker/work classified as critical to COVID-19 response: COVID2
##wave1_covid1yp_5045 d12: Participant is a keyworker; as defined by the government: COVID1
##wave2_covid2yp_6030 e3: Pp is a keyworker/work classified as critical to COVID-19 response: COVID2
table(alspac_children_v0001$wave0_covid1yp_5045, useNA="always")
##recoding missing
alspac_children_v0001$wave0_covid1yp_5045[alspac_children_v0001$wave0_covid1yp_5045<0 | alspac_children_v0001$wave0_covid1yp_5045==9] <- NA
alspac_children_v0001$wave0_covid2yp_6030[alspac_children_v0001$wave0_covid2yp_6030<0 | alspac_children_v0001$wave0_covid2yp_6030==9] <- NA
alspac_children_v0001$wave1_covid1yp_5045[alspac_children_v0001$wave1_covid1yp_5045<0 | alspac_children_v0001$wave1_covid1yp_5045==9] <- NA
alspac_children_v0001$wave2_covid2yp_6030[alspac_children_v0001$wave2_covid2yp_6030<0 | alspac_children_v0001$wave2_covid2yp_6030==9] <- NA
##recoding so that if participant reported being keyworker AT ANY WAVE, they are coded as key worker
alspac_children_v0001$new_keyworker <- NA
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==1 | alspac_children_v0001$wave0_covid2yp_6030==1 |
alspac_children_v0001$wave1_covid1yp_5045==1 | alspac_children_v0001$wave2_covid2yp_6030==1] <- 1
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & alspac_children_v0001$wave0_covid2yp_6030==2 &
alspac_children_v0001$wave1_covid1yp_5045==2 & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & alspac_children_v0001$wave0_covid2yp_6030==2 &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
alspac_children_v0001$wave1_covid1yp_5046==2 & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
alspac_children_v0001$wave1_covid1yp_5046==2 & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & alspac_children_v0001$wave0_covid2yp_6030==2 &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & alspac_children_v0001$wave0_covid2yp_6030==2 &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
alspac_children_v0001$wave1_covid1yp_5045==2 & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & alspac_children_v0001$wave0_covid2yp_6030==2 &
alspac_children_v0001$wave1_covid1yp_5045==2 & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
alspac_children_v0001$wave1_covid1yp_5045==2 & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
alspac_children_v0001$new_keyworker[is.na(alspac_children_v0001$wave0_covid1yp_5045) & alspac_children_v0001$wave0_covid2yp_6030==2 &
alspac_children_v0001$wave1_covid1yp_5045==2 & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & is.na(alspac_children_v0001$wave0_covid2yp_6030) &
alspac_children_v0001$wave1_covid1yp_5045==2 & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & alspac_children_v0001$wave0_covid2yp_6030==2 &
is.na(alspac_children_v0001$wave1_covid1yp_5045) & alspac_children_v0001$wave2_covid2yp_6030==2] <- 0
alspac_children_v0001$new_keyworker[alspac_children_v0001$wave0_covid1yp_5045==2 & alspac_children_v0001$wave0_covid2yp_6030==2 &
alspac_children_v0001$wave1_covid1yp_5045==2 & is.na(alspac_children_v0001$wave2_covid2yp_6030)] <- 0
table(alspac_children_v0001$new_keyworker, useNA="always")
alspac_children_v0001$new_keyworker <- add_labels(alspac_children_v0001$new_keyworker, labels=c("No"=0, "Yes"=1))
##---------------------------------------------------------------------------------------------------------
##PRE-PANDEMIC MENTAL HEALTH (1=EXCELLENT; 2=VERY GOOD; 3=GOOD; 4=FAIR, 5=POOR)
##---------------------------------------------------------------------------------------------------------
##USOC##
look_for(ukhls_v0003, "scghq", details="none")
##likert: j_scghq1_dv (cutoff 4+)
##caseness: j_scghq2_dv
table(ukhls_v0003$j_scghq2_dv)
##ELSA##
look_for(elsa_v0001, "cesd", details="none")
##wave9_p_cesd_sc: max score 8 cutoff >=3 indicates caseness
table(elsa_v0001$wave9_p_cesd_sc, useNA="always")
##ALSPAC CHILDREN##
##only pandemic available
look_for(alspac_children_v0001, "SMFQ", details="none")
##END