generated from opensafely/research-template
/
anaphylaxis_untreated_update.do
437 lines (373 loc) · 15.5 KB
/
anaphylaxis_untreated_update.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
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
********************************************************************************
*
* Do-file: data preparation and descriptives.do
*
* Project: sotrovimab-and-molnupiravir
*
* Programmed by: Bang Zheng
*
* Data used: output/input.csv
*
* Data created: output/main.dta (main analysis dataset)
*
* Other output: logs/data_preparation.log
*
********************************************************************************
*
* Purpose: This do-file creates the variables required for the
* main analysis and saves into Stata dataset, and describes
* variables by drug groups.
*
********************************************************************************
* Open a log file
cap log close
log using ./logs/anaphylaxis_untreated_update, replace t
clear
* import dataset
import delimited ./output/input_anaphylaxis_untreated_update.csv, delimiter(comma) varnames(1) case(preserve)
*codebook
drop if cancer_opensafely_snomed_new==""&immunosuppresant_drugs_nhsd==""&oral_steroid_drugs_nhsd==""&immunosupression_nhsd_new==""&solid_organ_transplant_nhsd_new==""&downs_syndrome_nhsd==""&haematological_disease_nhsd==""&ckd_stage_5_nhsd==""&liver_disease_nhsd==""&hiv_aids_nhsd==""&multiple_sclerosis_nhsd==""&motor_neurone_disease_nhsd==""&myasthenia_gravis_nhsd==""&huntingtons_disease_nhsd==""
* Convert strings to dates *
foreach var of varlist sotrovimab_covid_therapeutics molnupiravir_covid_therapeutics paxlovid_covid_therapeutics remdesivir_covid_therapeutics ///
casirivimab_covid_therapeutics date_treated start_date ///
death_date dereg_date last_vaccination_date ///
cancer_opensafely_snomed_new immunosuppresant_drugs_nhsd ///
oral_steroid_drugs_nhsd immunosupression_nhsd_new solid_organ_transplant_nhsd_new ///
downs_syndrome_nhsd haematological_disease_nhsd ckd_stage_5_nhsd liver_disease_nhsd hiv_aids_nhsd ///
multiple_sclerosis_nhsd motor_neurone_disease_nhsd myasthenia_gravis_nhsd huntingtons_disease_nhsd ///
death_with_anaphylaxis_date death_with_anaph_underly_date death_with_anaphylaxis_date2 ///
death_with_anaph_underly_date2 death_with_anaphylaxis_date3 death_with_anaphylaxis_date_pre death_with_anaph_underly_date_pr hospitalisation_anaph ///
hosp_discharge_anaph hospitalisation_anaph_underly hospitalisation_anaph2 hospitalisation_anaph_underly2 hospitalisation_anaph3 hospitalisation_anaph_pre ///
hosp_anaph_underly_pre AE_anaph AE_anaph2 AE_anaph3 AE_anaph4 AE_anaph_pre AE_anaph2_pre GP_anaph GP_anaph2 GP_anaph_pre GP_anaph2_pre ///
date_treated1 sotrovimab_covid_therapeutics1 molnupiravir_covid_therapeutics1 paxlovid_covid_therapeutics1 primary_covid_hospital_discharge primary_covid_hospital_admission ///
any_covid_hospital_discharge_dat any_covid_hospital_admission_dat hosp_anaph_pre_1y AE_anaph_pre_1y AE_anaph2_pre_1y GP_anaph_pre_1y {
capture confirm string variable `var'
if _rc==0 {
rename `var' a
gen `var' = date(a, "YMD")
drop a
format %td `var'
}
}
*the following date variables had no observation*
*hiv_aids_nhsd_icd10
*transplant_all_y_codes_opcs4
*transplant_thymus_opcs4
*transplant_conjunctiva_y_code_op
*transplant_conjunctiva_opcs4
*transplant_stomach_opcs4
*transplant_ileum_1_Y_codes_opcs4
*transplant_ileum_2_Y_codes_opcs4
*transplant_ileum_1_opcs4
*transplant_ileum_2_opcs4
*describe
*check hosp/death event date range*
codebook hospitalisation_anaph AE_anaph death_date last_vaccination_date
codebook hospitalisation_anaph AE_anaph death_date last_vaccination_date if registered_eligible==0
keep if registered_eligible==1
*describe COVID therapy*
gen treated=(date_treated!=.)
keep if treated==0
*exclusion criteria*
sum age,de
*keep if age>=18 & age<110
tab sex,m
*keep if sex=="F"|sex=="M"
tab has_died,m
*keep if has_died==0
*tab registered_eligible,m
*keep if registered_eligible==1
*tab covid_test_positive covid_positive_previous_30_days,m
*keep if covid_test_positive==1 & covid_positive_previous_30_days==0
*drop if primary_covid_hospital_discharge!=.|primary_covid_hospital_admission!=.
*drop if any_covid_hospital_admission_dat!=.|any_covid_hospital_discharge_dat!=.
keep if start_date>=mdy(12,16,2021)&start_date<=mdy(01,28,2023)
*10 high risk groups: downs_syndrome, solid_cancer, haematological_disease, renal_disease, liver_disease, imid,
*immunosupression, hiv_aids, solid_organ_transplant, rare_neurological_conditions, high_risk_group_combined
replace oral_steroid_drugs_nhsd=. if oral_steroid_drug_nhsd_3m_count < 2 & oral_steroid_drug_nhsd_12m_count < 4
gen imid_nhsd=min(oral_steroid_drugs_nhsd, immunosuppresant_drugs_nhsd)
gen rare_neuro_nhsd = min(multiple_sclerosis_nhsd, motor_neurone_disease_nhsd, myasthenia_gravis_nhsd, huntingtons_disease_nhsd)
*high risk group only based on codelists*
gen downs_syndrome=(downs_syndrome_nhsd<=start_date)
gen solid_cancer_new=(cancer_opensafely_snomed_new<=start_date)
gen haema_disease=( haematological_disease_nhsd <=start_date)
gen renal_disease=( ckd_stage_5_nhsd <=start_date)
gen liver_disease=( liver_disease_nhsd <=start_date)
gen imid=( imid_nhsd <=start_date)
gen immunosupression_new=( immunosupression_nhsd_new <=start_date)
gen hiv_aids=( hiv_aids_nhsd <=start_date)
gen solid_organ_new=( solid_organ_transplant_nhsd_new<=start_date)
gen rare_neuro=( rare_neuro_nhsd <=start_date)
gen high_risk_group_new=(( downs_syndrome + solid_cancer_new + haema_disease + renal_disease + liver_disease + imid + immunosupression_new + hiv_aids + solid_organ_new + rare_neuro )>0)
tab high_risk_group_new,m
keep if high_risk_group_new==1
*anaphylaxis events*
*death *
sum death_with_anaphylaxis_date,f
gen death=(death_with_anaphylaxis_date!=.)
tab death
gen day_death=death_with_anaphylaxis_date-start_date
sum day_death, de
gen death_28d=(death_with_anaphylaxis_date!=.&day_death<=28)
tab death_28d
sum death_with_anaph_underly_date ,f
sum death_with_anaph_underly_date if day_death<=28,f
sum death_with_anaphylaxis_date2 ,f
sum death_with_anaph_underly_date2 ,f
sum death_with_anaphylaxis_date3 ,f
sum death_with_anaphylaxis_date_pre ,f
sum death_with_anaph_underly_date_pr ,f
*hosp*
sum hospitalisation_anaph ,f
gen hosp=(hospitalisation_anaph!=.)
tab hosp
gen day_hosp=hospitalisation_anaph-start_date
sum day_hosp, de
gen hosp_28d=(hospitalisation_anaph!=.&day_hosp<=28)
tab hosp_28d
tab hospitalisation_anaph if hosp_28d==1
gen day_discharge=hosp_discharge_anaph-hospitalisation_anaph
sum day_discharge,de
sum hospitalisation_anaph_underly ,f
sum hospitalisation_anaph_underly if day_hosp<=28,f
sum hospitalisation_anaph2 ,f
sum hospitalisation_anaph2 if day_hosp<=28,f
sum hospitalisation_anaph_underly2 ,f
sum hospitalisation_anaph3 ,f
sum hospitalisation_anaph3 if day_hosp<=28,f
sum hospitalisation_anaph_pre ,f
sum hosp_anaph_underly_pre ,f
sum hosp_anaph_pre_1y,f
*A&E*
sum AE_anaph ,f
gen AE=(AE_anaph!=.)
tab AE
gen day_AE=AE_anaph-start_date
sum day_AE, de
gen AE_28d=(AE_anaph!=.&day_AE<=28)
tab AE_28d
tab AE_anaph if AE_28d==1
sum AE_anaph2 ,f
sum AE_anaph3 ,f
sum AE_anaph4 ,f
gen AE_28d2=(AE_anaph2!=.&day_AE<=28)
tab AE_28d2
tab AE_anaph if AE_28d2==1
sum AE_anaph2 if day_AE<=28,f
sum AE_anaph3 if day_AE<=28,f
sum AE_anaph4 if day_AE<=28,f
sum AE_anaph_pre ,f
sum AE_anaph2_pre ,f
sum AE_anaph_pre_1y, f
sum AE_anaph2_pre_1y, f
*GP*
sum GP_anaph ,f
gen GP=(GP_anaph!=.)
tab GP
gen day_GP=GP_anaph-start_date
sum day_GP, de
gen GP_28d=(GP_anaph!=.&day_GP<=28)
tab GP_28d
tab GP_anaph if GP_28d==1
tostring GP_anaph_code,replace
tab GP_anaph_code ,m
tab GP_anaph_code if day_GP<=28,m
sum GP_anaph2 ,f
sum GP_anaph2 if day_GP<=28,f
sum GP_anaph_pre ,f
sum GP_anaph2_pre ,f
sum GP_anaph_pre_1y, f
*combine 4 data sources*
tab hosp_28d AE_28d,row
tab hosp_28d AE_28d2,row
tab hosp_28d GP_28d,row
tab AE_28d GP_28d,row
tab AE_28d2 GP_28d,row
gen anaph_all=(death_28d+hosp_28d+AE_28d+GP_28d)>0
tab anaph_all
gen anaph_all2=(death_28d+hosp_28d+AE_28d2+GP_28d)>0
tab anaph_all2
gen anaph_ever=(hospitalisation_anaph_pre!=.|AE_anaph_pre!=.|GP_anaph_pre!=.)
tab anaph_ever
gen anaph_ever2=(hospitalisation_anaph_pre!=.|AE_anaph2_pre!=.|GP_anaph_pre!=.)
tab anaph_ever2
gen anaph_pre_1y=(hosp_anaph_pre_1y!=.|AE_anaph_pre_1y!=.|GP_anaph_pre_1y!=.)
tab anaph_pre_1y
gen anaph_pre_1y2=(hosp_anaph_pre_1y!=.|AE_anaph2_pre_1y!=.|GP_anaph_pre_1y!=.)
tab anaph_pre_1y2
tab anaph_ever2 anaph_all2
tab anaph_pre_1y2 anaph_all2
*exclusion*
clear
* import dataset
import delimited ./output/input_anaphylaxis_untreated_update.csv, delimiter(comma) varnames(1) case(preserve)
*codebook
drop if cancer_opensafely_snomed_new==""&immunosuppresant_drugs_nhsd==""&oral_steroid_drugs_nhsd==""&immunosupression_nhsd_new==""&solid_organ_transplant_nhsd_new==""&downs_syndrome_nhsd==""&haematological_disease_nhsd==""&ckd_stage_5_nhsd==""&liver_disease_nhsd==""&hiv_aids_nhsd==""&multiple_sclerosis_nhsd==""&motor_neurone_disease_nhsd==""&myasthenia_gravis_nhsd==""&huntingtons_disease_nhsd==""
* Convert strings to dates *
foreach var of varlist sotrovimab_covid_therapeutics molnupiravir_covid_therapeutics paxlovid_covid_therapeutics remdesivir_covid_therapeutics ///
casirivimab_covid_therapeutics date_treated start_date ///
death_date dereg_date last_vaccination_date ///
cancer_opensafely_snomed_new immunosuppresant_drugs_nhsd ///
oral_steroid_drugs_nhsd immunosupression_nhsd_new solid_organ_transplant_nhsd_new ///
downs_syndrome_nhsd haematological_disease_nhsd ckd_stage_5_nhsd liver_disease_nhsd hiv_aids_nhsd ///
multiple_sclerosis_nhsd motor_neurone_disease_nhsd myasthenia_gravis_nhsd huntingtons_disease_nhsd ///
death_with_anaphylaxis_date death_with_anaph_underly_date death_with_anaphylaxis_date2 ///
death_with_anaph_underly_date2 death_with_anaphylaxis_date3 death_with_anaphylaxis_date_pre death_with_anaph_underly_date_pr hospitalisation_anaph ///
hosp_discharge_anaph hospitalisation_anaph_underly hospitalisation_anaph2 hospitalisation_anaph_underly2 hospitalisation_anaph3 hospitalisation_anaph_pre ///
hosp_anaph_underly_pre AE_anaph AE_anaph2 AE_anaph3 AE_anaph4 AE_anaph_pre AE_anaph2_pre GP_anaph GP_anaph2 GP_anaph_pre GP_anaph2_pre ///
date_treated1 sotrovimab_covid_therapeutics1 molnupiravir_covid_therapeutics1 paxlovid_covid_therapeutics1 primary_covid_hospital_discharge primary_covid_hospital_admission ///
any_covid_hospital_discharge_dat any_covid_hospital_admission_dat hosp_anaph_pre_1y AE_anaph_pre_1y AE_anaph2_pre_1y GP_anaph_pre_1y {
capture confirm string variable `var'
if _rc==0 {
rename `var' a
gen `var' = date(a, "YMD")
drop a
format %td `var'
}
}
*the following date variables had no observation*
*hiv_aids_nhsd_icd10
*transplant_all_y_codes_opcs4
*transplant_thymus_opcs4
*transplant_conjunctiva_y_code_op
*transplant_conjunctiva_opcs4
*transplant_stomach_opcs4
*transplant_ileum_1_Y_codes_opcs4
*transplant_ileum_2_Y_codes_opcs4
*transplant_ileum_1_opcs4
*transplant_ileum_2_opcs4
keep if registered_eligible==1
*describe COVID therapy*
gen treated=(date_treated1!=.)
keep if treated==0
*exclusion criteria*
sum age,de
*keep if age>=18 & age<110
tab sex,m
*keep if sex=="F"|sex=="M"
tab has_died,m
*keep if has_died==0
*tab registered_eligible,m
*keep if registered_eligible==1
*tab covid_test_positive covid_positive_previous_30_days,m
*keep if covid_test_positive==1 & covid_positive_previous_30_days==0
drop if primary_covid_hospital_discharge!=.|primary_covid_hospital_admission!=.
drop if any_covid_hospital_admission_dat!=.|any_covid_hospital_discharge_dat!=.
keep if start_date>=mdy(12,16,2021)&start_date<=mdy(01,28,2023)
*10 high risk groups: downs_syndrome, solid_cancer, haematological_disease, renal_disease, liver_disease, imid,
*immunosupression, hiv_aids, solid_organ_transplant, rare_neurological_conditions, high_risk_group_combined
replace oral_steroid_drugs_nhsd=. if oral_steroid_drug_nhsd_3m_count < 2 & oral_steroid_drug_nhsd_12m_count < 4
gen imid_nhsd=min(oral_steroid_drugs_nhsd, immunosuppresant_drugs_nhsd)
gen rare_neuro_nhsd = min(multiple_sclerosis_nhsd, motor_neurone_disease_nhsd, myasthenia_gravis_nhsd, huntingtons_disease_nhsd)
*high risk group only based on codelists*
gen downs_syndrome=(downs_syndrome_nhsd<=start_date)
gen solid_cancer_new=(cancer_opensafely_snomed_new<=start_date)
gen haema_disease=( haematological_disease_nhsd <=start_date)
gen renal_disease=( ckd_stage_5_nhsd <=start_date)
gen liver_disease=( liver_disease_nhsd <=start_date)
gen imid=( imid_nhsd <=start_date)
gen immunosupression_new=( immunosupression_nhsd_new <=start_date)
gen hiv_aids=( hiv_aids_nhsd <=start_date)
gen solid_organ_new=( solid_organ_transplant_nhsd_new<=start_date)
gen rare_neuro=( rare_neuro_nhsd <=start_date)
gen high_risk_group_new=(( downs_syndrome + solid_cancer_new + haema_disease + renal_disease + liver_disease + imid + immunosupression_new + hiv_aids + solid_organ_new + rare_neuro )>0)
tab high_risk_group_new,m
keep if high_risk_group_new==1
*anaphylaxis events*
*death *
sum death_with_anaphylaxis_date,f
gen death=(death_with_anaphylaxis_date!=.)
tab death
gen day_death=death_with_anaphylaxis_date-start_date
sum day_death, de
gen death_28d=(death_with_anaphylaxis_date!=.&day_death<=28)
tab death_28d
sum death_with_anaph_underly_date ,f
sum death_with_anaph_underly_date if day_death<=28,f
sum death_with_anaphylaxis_date2 ,f
sum death_with_anaph_underly_date2 ,f
sum death_with_anaphylaxis_date3 ,f
sum death_with_anaphylaxis_date_pre ,f
sum death_with_anaph_underly_date_pr ,f
*hosp*
sum hospitalisation_anaph ,f
gen hosp=(hospitalisation_anaph!=.)
tab hosp
gen day_hosp=hospitalisation_anaph-start_date
sum day_hosp, de
gen hosp_28d=(hospitalisation_anaph!=.&day_hosp<=28)
tab hosp_28d
tab hospitalisation_anaph if hosp_28d==1
gen day_discharge=hosp_discharge_anaph-hospitalisation_anaph
sum day_discharge,de
sum hospitalisation_anaph_underly ,f
sum hospitalisation_anaph_underly if day_hosp<=28,f
sum hospitalisation_anaph2 ,f
sum hospitalisation_anaph2 if day_hosp<=28,f
sum hospitalisation_anaph_underly2 ,f
sum hospitalisation_anaph3 ,f
sum hospitalisation_anaph3 if day_hosp<=28,f
sum hospitalisation_anaph_pre ,f
sum hosp_anaph_underly_pre ,f
sum hosp_anaph_pre_1y,f
*A&E*
sum AE_anaph ,f
gen AE=(AE_anaph!=.)
tab AE
gen day_AE=AE_anaph-start_date
sum day_AE, de
gen AE_28d=(AE_anaph!=.&day_AE<=28)
tab AE_28d
tab AE_anaph if AE_28d==1
sum AE_anaph2 ,f
sum AE_anaph3 ,f
sum AE_anaph4 ,f
gen AE_28d2=(AE_anaph2!=.&day_AE<=28)
tab AE_28d2
tab AE_anaph if AE_28d2==1
sum AE_anaph2 if day_AE<=28,f
sum AE_anaph3 if day_AE<=28,f
sum AE_anaph4 if day_AE<=28,f
sum AE_anaph_pre ,f
sum AE_anaph2_pre ,f
sum AE_anaph_pre_1y, f
sum AE_anaph2_pre_1y, f
*GP*
sum GP_anaph ,f
gen GP=(GP_anaph!=.)
tab GP
gen day_GP=GP_anaph-start_date
sum day_GP, de
gen GP_28d=(GP_anaph!=.&day_GP<=28)
tab GP_28d
tab GP_anaph if GP_28d==1
tostring GP_anaph_code,replace
tab GP_anaph_code ,m
tab GP_anaph_code if day_GP<=28,m
sum GP_anaph2 ,f
sum GP_anaph2 if day_GP<=28,f
sum GP_anaph_pre ,f
sum GP_anaph2_pre ,f
sum GP_anaph_pre_1y, f
*combine 4 data sources*
tab hosp_28d AE_28d,row
tab hosp_28d AE_28d2,row
tab hosp_28d GP_28d,row
tab AE_28d GP_28d,row
tab AE_28d2 GP_28d,row
gen anaph_all=(death_28d+hosp_28d+AE_28d+GP_28d)>0
tab anaph_all
gen anaph_all2=(death_28d+hosp_28d+AE_28d2+GP_28d)>0
tab anaph_all2
gen anaph_ever=(hospitalisation_anaph_pre!=.|AE_anaph_pre!=.|GP_anaph_pre!=.)
tab anaph_ever
gen anaph_ever2=(hospitalisation_anaph_pre!=.|AE_anaph2_pre!=.|GP_anaph_pre!=.)
tab anaph_ever2
gen anaph_pre_1y=(hosp_anaph_pre_1y!=.|AE_anaph_pre_1y!=.|GP_anaph_pre_1y!=.)
tab anaph_pre_1y
gen anaph_pre_1y2=(hosp_anaph_pre_1y!=.|AE_anaph2_pre_1y!=.|GP_anaph_pre_1y!=.)
tab anaph_pre_1y2
tab anaph_ever2 anaph_all2
tab anaph_pre_1y2 anaph_all2
*by age*
log close