generated from opensafely/research-template
/
204_cox_model.do
837 lines (753 loc) · 34.6 KB
/
204_cox_model.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
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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
********************************************************************************
*
* Do-file: cox model
* Project: Sotrovimab-Paxlovid-Molnupiravir
* Date: 06/4/23
* Programmed by: Katie Bechman
* Description: run cox models
* Data used: main.dta
* Data created: coxoutput
* Other output: logfiles, printed to folder $Logdir
* User installed ado: (place .ado file(s) in analysis folder)
****************************************************************************************************************
// global projectdir "C:\Users\k1635179\OneDrive - King's College London\Katie\OpenSafely\Safety mAB and antivirals\Safety-Sotrovimab-Paxlovid-Molnupiravir"
global projectdir `c(pwd)'
di "$projectdir"
capture mkdir "$projectdir/output/data"
capture mkdir "$projectdir/output/figures"
capture mkdir "$projectdir/output/tables"
global logdir "$projectdir/logs"
di "$logdir"
* Open a log file
cap log close
log using "$logdir/cox_model.log", replace
*Set Ado file path
adopath + "$projectdir/analysis/ado"
* SET Index date
global indexdate = "01/03/2020"
use "$projectdir/output/data/main.dta", clear
* Models
global crude i.drug
global agesex i.drug age i.sex
global adj i.drug age i.sex i.region_nhs i.imdq5 White 1b.bmi_group ///
paxlovid_contraindicated i.vaccination_status diabetes chronic_cardiac_disease chronic_respiratory_disease hypertension ///
downs_syndrome solid_cancer haem_disease renal_disease liver_disease imid_on_drug immunosuppression hiv_aids organ_transplant rare_neuro
global adj2 i.drug age i.sex i.region_nhs i.imdq5 White 1b.bmi_group
global adj3 i.drug age i.sex i.region_nhs i.imdq5 White 1b.bmi_group ///
paxlovid_contraindicated i.vaccination_status diabetes chronic_cardiac_disease chronic_respiratory_disease hypertension
global adj4 i.drug age i.sex i.region_nhs i.imdq5 White 1b.bmi_group ///
paxlovid_contraindicated i.vaccination_status diabetes chronic_cardiac_disease chronic_respiratory_disease hypertension ///
downs_syndrome solid_cancer haem_disease renal_disease liver_disease imid_on_drug immunosuppression hiv_aids organ_transplant rare_neuro ///
dementia care_home serious_mental_illness
* Outcome
global ae_disease ae_diverticulitis ///
ae_diarrhoea ///
ae_taste ///
ae_rash ///
ae_bronchospasm ///
ae_contactderm ///
ae_dizziness ///
ae_nausea_vomit ///
ae_headache ///
ae_anaphylaxis ///
ae_drugreaction ///
ae_ra ///
ae_sle ///
ae_psorasis ///
ae_psa ///
ae_axspa ///
ae_ibd
global ae_disease_serious ae_diverticulitis_serious ///
ae_diarrhoea_serious ///
ae_taste_serious ///
ae_rash_serious ///
ae_contactderm_serious ///
ae_dizziness_serious ///
ae_nausea_vomit_serious ///
ae_headache_serious ///
ae_anaphylaxis_serious ///
ae_drugreaction_serious ///
ae_ra_serious ///
ae_sle_serious ///
ae_psorasis_serious ///
ae_psa_serious ///
ae_axspa_serious ///
ae_ibd_serious
global ae_combined ae_all ///
ae_all_serious ///
ae_spc_all ///
ae_spc_serious ///
ae_drug_all ///
ae_drug_serious ///
ae_imae_all ///
ae_imae_serious
*******************************************************************************************************************
** MAIN ANALYSIS **
tab drug covid_test
tab eligible
tab drug pre_drug_test
tab drug paxlovid_contraindicated
*** Graphs - Schoenfeld Residual & log-log plot
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stcox i.drug
estat phtest,de
estat phtest, plot(1.drug) ytitle("Scaled Schoenfeld Residual, Sotrovimab", size(small)) name(schoenfeld_sot_`fail', replace)
estat phtest, plot(2.drug) ytitle("Scaled Schoenfeld Residual, Paxlovid",size(small)) name(schoenfeld_pax_`fail', replace)
estat phtest, plot(3.drug) ytitle("Scaled Schoenfeld Residual, Molnupiravir",size(small)) name(schoenfeld_mol_`fail', replace)
graph combine schoenfeld_sot_`fail' schoenfeld_pax_`fail' schoenfeld_mol_`fail', title("Schoenfeld Residual `fail'") saving("$projectdir/output/figures/schoenfield_`fail'", replace)
graph export "$projectdir/output/figures/schoenfield_`fail'.svg", as(svg) replace
stphplot, by(drug) legend(order(1 "Control" 2 "Sotrovimab" 3 "Paxlovid" 4 "Molnupiravir") symxsize(*0.4) size(small)) title ("log-log plot `fail'") saving("$projectdir/output/figures/loglog_plot_`fail'", replace)
graph export "$projectdir/output/figures/loglog_plot_`fail'.svg", as(svg) replace
}
*** Hazard of events
tempname cox_model_summary
postfile `cox_model_summary' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary", replace
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in crude agesex adj adj2 adj3 adj4{
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary'
tempname cox_model_disease
postfile `cox_model_disease' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_disease", replace
foreach fail in $ae_diseaseae_ $ae_disease_serious {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in crude agesex adj {
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_disease' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_disease'
*** Rates of events
tempname coxoutput_rates
postfile `coxoutput_rates' str20(failure) ///
all_ptime all_events all_rate all_lci all_uci ///
control_ptime control_events control_rate control_lci_ control_uci ///
sot_ptime sot_events sot_rate sot_lci sot_uci ///
pax_ptime pax_events pax_rate pax_lci pax_uci ///
mol_ptime mol_events mol_rate mol_lci mol_uci ///
using "$projectdir/output/tables/cox_model_rates", replace
foreach fail in $ae_disease $ae_disease_serious $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stptime
local all_rate = `r(rate)'
local all_ptime = `r(ptime)'
local all_lci = `r(lb)'
local all_uci = `r(ub)'
local all_events = `r(failures)'
stptime if drug == 0
local control_rate = `r(rate)'
local control_ptime = `r(ptime)'
local control_lci = `r(lb)'
local control_uci = `r(ub)'
local control_events = `r(failures)'
display "no drug"
stptime if drug == 1
local sot_rate = `r(rate)'
local sot_ptime = `r(ptime)'
local sot_lci = `r(lb)'
local sot_uci = `r(ub)'
local sot_events = `r(failures)'
display "sotrovimab"
stptime if drug == 2
local pax_rate = `r(rate)'
local pax_ptime = `r(ptime)'
local pax_lci = `r(lb)'
local pax_uci = `r(ub)'
local pax_events = `r(failures)'
display "paxlovid"
stptime if drug == 3
local mol_rate = `r(rate)'
local mol_ptime = `r(ptime)'
local mol_lci = `r(lb)'
local mol_uci = `r(ub)'
local mol_events = `r(failures)'
display "molnupavir"
post `coxoutput_rates' ("`fail'") (`all_ptime') (`all_events') (`all_rate') (`all_lci') (`all_uci') ///
(`control_ptime') (`control_events') (`control_rate') (`control_lci') (`control_uci') ///
(`sot_ptime') (`sot_events') (`sot_rate') (`sot_lci') (`sot_uci') ///
(`pax_ptime') (`pax_events') (`pax_rate') (`pax_lci') (`pax_uci') ///
(`mol_ptime') (`mol_events') (`mol_rate') (`mol_lci') (`mol_uci')
}
postclose `coxoutput_rates'
*** Redact and save
use "$projectdir/output/tables/cox_model_summary", clear
save "$projectdir/output/tables/cox_model_summary", replace
export delimited using "$projectdir/output/tables/cox_model_summary.csv", replace
use "$projectdir/output/tables/cox_model_disease", clear
save "$projectdir/output/tables/cox_model_disease", replace
export delimited using "$projectdir/output/tables/cox_model_disease.csv", replace
use "$projectdir/output/tables/cox_model_rates", clear
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates", replace
export delimited using "$projectdir/output/tables/cox_model_rates.csv", replace
use "$projectdir/output/tables/cox_model_rates", clear
foreach var of varlist *events *ptime {
gen `var'_midpoint = (ceil(`var'/6)*6) - (floor(6/2) * (`var'!=0))
}
foreach var in all control sot pax mol {
gen `var'_rate_midpoint = (`var'_events_midpoint/`var'_ptime_midpoint)*1000
gen `var'_lci_midpoint = (invpoisson(`var'_events_midpoint,.975)/`var'_ptime_midpoint)*1000
gen `var'_uci_midpoint = (invpoisson(`var'_events_midpoint,.025)/`var'_ptime_midpoint)*1000
}
keep failure *midpoint
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_round", replace
export delimited using "$projectdir/output/tables/cox_model_rates_round.csv", replace
*******************************************************************************************************************
** SENSITIVITY ANALYSIS 1 = Treatment group start date on treatment date. Control group start date delayed by median delay between test and treat in treat group **
use "$projectdir/output/data/sensitivity_analysis.dta", clear
tab median_delay_all
gen start_date_delay = start_date + median_delay_all if drug==0
count if date_treated==. &drug>0
replace start_date_delay = date_treat if drug>0
*** Hazard of events
tempname cox_model_summary_sens_1
postfile `cox_model_summary_sens_1' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary_sens_1", replace
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date_delay) enter(time start_date_delay) failure(fail_`fail'==1)
foreach model in crude agesex adj {
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary_sens_1' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary_sens_1'
tempname cox_model_disease_sens_1
postfile `cox_model_disease_sens_1' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_disease_sens_1", replace
foreach fail in $ae_diseaseae_ $ae_disease_serious {
stset stop_`fail', id(patient_id) origin(time start_date_delay) enter(time start_date_delay) failure(fail_`fail'==1)
foreach model in crude agesex adj {
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_disease_sens_1' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_disease_sens_1'
*** Rates of events
tempname coxoutput_rates_sens_1
postfile `coxoutput_rates_sens_1' str20(failure) ///
all_ptime all_events all_rate all_lci all_uci ///
control_ptime control_events control_rate control_lci_ control_uci ///
sot_ptime sot_events sot_rate sot_lci sot_uci ///
pax_ptime pax_events pax_rate pax_lci pax_uci ///
mol_ptime mol_events mol_rate mol_lci mol_uci ///
using "$projectdir/output/tables/cox_model_rates_sens_1", replace
foreach fail in $ae_disease $ae_disease_serious $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date_delay) enter(time start_date_delay) failure(fail_`fail'==1)
stptime
local all_rate = `r(rate)'
local all_ptime = `r(ptime)'
local all_lci = `r(lb)'
local all_uci = `r(ub)'
local all_events = `r(failures)'
stptime if drug == 0
local control_rate = `r(rate)'
local control_ptime = `r(ptime)'
local control_lci = `r(lb)'
local control_uci = `r(ub)'
local control_events = `r(failures)'
display "no drug"
stptime if drug == 1
local sot_rate = `r(rate)'
local sot_ptime = `r(ptime)'
local sot_lci = `r(lb)'
local sot_uci = `r(ub)'
local sot_events = `r(failures)'
display "sotrovimab"
stptime if drug == 2
local pax_rate = `r(rate)'
local pax_ptime = `r(ptime)'
local pax_lci = `r(lb)'
local pax_uci = `r(ub)'
local pax_events = `r(failures)'
display "paxlovid"
stptime if drug == 3
local mol_rate = `r(rate)'
local mol_ptime = `r(ptime)'
local mol_lci = `r(lb)'
local mol_uci = `r(ub)'
local mol_events = `r(failures)'
display "molnupavir"
post `coxoutput_rates_sens_1' ("`fail'") (`all_ptime') (`all_events') (`all_rate') (`all_lci') (`all_uci') ///
(`control_ptime') (`control_events') (`control_rate') (`control_lci') (`control_uci') ///
(`sot_ptime') (`sot_events') (`sot_rate') (`sot_lci') (`sot_uci') ///
(`pax_ptime') (`pax_events') (`pax_rate') (`pax_lci') (`pax_uci') ///
(`mol_ptime') (`mol_events') (`mol_rate') (`mol_lci') (`mol_uci')
}
postclose `coxoutput_rates_sens_1'
*** Redact and save
use "$projectdir/output/tables/cox_model_summary_sens_1", clear
save "$projectdir/output/tables/cox_model_summary_sens_1", replace
export delimited using "$projectdir/output/tables/cox_model_summary_sens_1.csv", replace
use "$projectdir/output/tables/cox_model_disease_sens_1", clear
save "$projectdir/output/tables/cox_model_disease_sens_1", replace
export delimited using "$projectdir/output/tables/cox_model_disease_sens_1.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_1", clear
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_sens_1", replace
export delimited using "$projectdir/output/tables/cox_model_rates_sens_1.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_1", clear
foreach var of varlist *events *ptime {
gen `var'_midpoint = (ceil(`var'/6)*6) - (floor(6/2) * (`var'!=0))
}
foreach var in all control sot pax mol {
gen `var'_rate_midpoint = (`var'_events_midpoint/`var'_ptime_midpoint)*1000
gen `var'_lci_midpoint = (invpoisson(`var'_events_midpoint,.975)/`var'_ptime_midpoint)*1000
gen `var'_uci_midpoint = (invpoisson(`var'_events_midpoint,.025)/`var'_ptime_midpoint)*1000
}
keep failure *midpoint
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_round_sens_1", replace
export delimited using "$projectdir/output/tables/cox_model_rates_round_sens_1.csv", replace
**************************************************************************************************************************************************************************************************************************************
** SENSITIVITY ANALYSIS 2 = time lag **
use "$projectdir/output/data/main.dta", clear
** Hazard of events with 1 day lag
tempname cox_model_summary_sens_2a
postfile `cox_model_summary_sens_2a' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary_sens_2a", replace
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in adj {
stcox $`model' if _t>=2, vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary_sens_2a' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary_sens_2a'
** Hazard of events with 2 day lag
tempname cox_model_summary_sens_2b
postfile `cox_model_summary_sens_2b' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary_sens_2b", replace
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in adj {
stcox $`model' if _t>=3, vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary_sens_2b' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary_sens_2b'
*** Redact and save
use "$projectdir/output/tables/cox_model_summary_sens_2a", clear
gen lag = 1
append using "$projectdir/output/tables/cox_model_summary_sens_2b"
replace lag =2 if lag==.
save "$projectdir/output/tables/cox_model_summary_sens_2", replace
export delimited using "$projectdir/output/tables/cox_model_summary_sens_2.csv", replace
*******************************************************************************************************************
** SENSITIVITY ANALYSIS 3 == time varying covariate **
use "$projectdir/output/data/main.dta", clear
** Hazard of events using stsplit
foreach fail in $ae_combined {
preserve
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stsplit time_`fail', at(1(1)5)
tab _t time_`fail'
foreach model in adj {
bys time_`fail': stcox $`model', vce(robust)
//stcox i.drug $`model' if time_`fail==1, vce(robust)
restore
}
}
use "$projectdir/output/data/main.dta", clear
** Hazard of events using tvc
foreach fail in $ae_combined {
preserve
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stsplit time_`fail', at(1(1)5)
replace _t=1 if _t==0.75
foreach model in adj {
stcox $`model', tvc(i.time_`fail') vce(robust)
restore
}
}
*******************************************************************************************************************
** SENSITIVITY ANALYSIS 4 == restrict to eligible and pax contraindicated **
use "$projectdir/output/data/main.dta", clear
tab drug paxlovid_contraindicated
tab drug eligible
*** Hazard of events
tempname cox_model_summary_sens_4
postfile `cox_model_summary_sens_4' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary_sens_4", replace
foreach fail in $ae_combined {
stset stop_`fail' if eligible==1 & paxlovid_contraindicated==0, id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in crude agesex adj{
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary_sens_4' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary_sens_4'
**** Rates of events
tempname coxoutput_rates_sens_4
postfile `coxoutput_rates_sens_4' str20(failure) ///
all_ptime all_events all_rate all_lci all_uci ///
control_ptime control_events control_rate control_lci_ control_uci ///
sot_ptime sot_events sot_rate sot_lci sot_uci ///
pax_ptime pax_events pax_rate pax_lci pax_uci ///
mol_ptime mol_events mol_rate mol_lci mol_uci ///
using "$projectdir/output/tables/cox_model_rates_sens_4", replace
foreach fail in $ae_disease $ae_disease_serious $ae_combined {
stset stop_`fail' if eligible==1 & paxlovid_contraindicated==0, id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stptime
local all_rate = `r(rate)'
local all_ptime = `r(ptime)'
local all_lci = `r(lb)'
local all_uci = `r(ub)'
local all_events = `r(failures)'
stptime if drug == 0
local control_rate = `r(rate)'
local control_ptime = `r(ptime)'
local control_lci = `r(lb)'
local control_uci = `r(ub)'
local control_events = `r(failures)'
display "no drug"
stptime if drug == 1
local sot_rate = `r(rate)'
local sot_ptime = `r(ptime)'
local sot_lci = `r(lb)'
local sot_uci = `r(ub)'
local sot_events = `r(failures)'
display "sotrovimab"
stptime if drug == 2
local pax_rate = `r(rate)'
local pax_ptime = `r(ptime)'
local pax_lci = `r(lb)'
local pax_uci = `r(ub)'
local pax_events = `r(failures)'
display "paxlovid"
stptime if drug == 3
local mol_rate = `r(rate)'
local mol_ptime = `r(ptime)'
local mol_lci = `r(lb)'
local mol_uci = `r(ub)'
local mol_events = `r(failures)'
display "molnupavir"
post `coxoutput_rates_sens_4' ("`fail'") (`all_ptime') (`all_events') (`all_rate') (`all_lci') (`all_uci') ///
(`control_ptime') (`control_events') (`control_rate') (`control_lci') (`control_uci') ///
(`sot_ptime') (`sot_events') (`sot_rate') (`sot_lci') (`sot_uci') ///
(`pax_ptime') (`pax_events') (`pax_rate') (`pax_lci') (`pax_uci') ///
(`mol_ptime') (`mol_events') (`mol_rate') (`mol_lci') (`mol_uci')
}
postclose `coxoutput_rates_sens_4'
*** Redact and save
use "$projectdir/output/tables/cox_model_summary_sens_4", clear
save "$projectdir/output/tables/cox_model_summary_sens_4", replace
export delimited using "$projectdir/output/tables/cox_model_summary_sens_4.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_4", clear
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_sens_4", replace
export delimited using "$projectdir/output/tables/cox_model_rates_sens_4.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_4", clear
foreach var of varlist *events *ptime {
gen `var'_midpoint = (ceil(`var'/6)*6) - (floor(6/2) * (`var'!=0))
}
foreach var in all control sot pax mol {
gen `var'_rate_midpoint = (`var'_events_midpoint/`var'_ptime_midpoint)*1000
gen `var'_lci_midpoint = (invpoisson(`var'_events_midpoint,.975)/`var'_ptime_midpoint)*1000
gen `var'_uci_midpoint = (invpoisson(`var'_events_midpoint,.025)/`var'_ptime_midpoint)*1000
}
keep failure *midpoint
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_round_sens_4", replace
export delimited using "$projectdir/output/tables/cox_model_rates_round_sens_4.csv", replace
*******************************************************************************************************************
** SENSITIVITY ANALYSIS 5 == unrestricted to covid positive date. Start date for treatment is TREAT DATE **
use "$projectdir/output/data/sensitivity_analysis.dta", clear
tab drug pre_drug_test
tab drug paxlovid_contraindicated
tab drug eligible
*** Hazard of events
tempname cox_model_summary_sens_5
postfile `cox_model_summary_sens_5' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary_sens_5", replace
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in crude agesex adj{
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary_sens_5' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary_sens_5'
**** Rates of events
tempname coxoutput_rates_sens_5
postfile `coxoutput_rates_sens_5' str20(failure) ///
all_ptime all_events all_rate all_lci all_uci ///
control_ptime control_events control_rate control_lci_ control_uci ///
sot_ptime sot_events sot_rate sot_lci sot_uci ///
pax_ptime pax_events pax_rate pax_lci pax_uci ///
mol_ptime mol_events mol_rate mol_lci mol_uci ///
using "$projectdir/output/tables/cox_model_rates_sens_5", replace
foreach fail in $ae_disease $ae_disease_serious $ae_combined {
stset stop_`fail' if eligible==1 & paxlovid_contraindicated==0, id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stptime
local all_rate = `r(rate)'
local all_ptime = `r(ptime)'
local all_lci = `r(lb)'
local all_uci = `r(ub)'
local all_events = `r(failures)'
stptime if drug == 0
local control_rate = `r(rate)'
local control_ptime = `r(ptime)'
local control_lci = `r(lb)'
local control_uci = `r(ub)'
local control_events = `r(failures)'
display "no drug"
stptime if drug == 1
local sot_rate = `r(rate)'
local sot_ptime = `r(ptime)'
local sot_lci = `r(lb)'
local sot_uci = `r(ub)'
local sot_events = `r(failures)'
display "sotrovimab"
stptime if drug == 2
local pax_rate = `r(rate)'
local pax_ptime = `r(ptime)'
local pax_lci = `r(lb)'
local pax_uci = `r(ub)'
local pax_events = `r(failures)'
display "paxlovid"
stptime if drug == 3
local mol_rate = `r(rate)'
local mol_ptime = `r(ptime)'
local mol_lci = `r(lb)'
local mol_uci = `r(ub)'
local mol_events = `r(failures)'
display "molnupavir"
post `coxoutput_rates_sens_5' ("`fail'") (`all_ptime') (`all_events') (`all_rate') (`all_lci') (`all_uci') ///
(`control_ptime') (`control_events') (`control_rate') (`control_lci') (`control_uci') ///
(`sot_ptime') (`sot_events') (`sot_rate') (`sot_lci') (`sot_uci') ///
(`pax_ptime') (`pax_events') (`pax_rate') (`pax_lci') (`pax_uci') ///
(`mol_ptime') (`mol_events') (`mol_rate') (`mol_lci') (`mol_uci')
}
postclose `coxoutput_rates_sens_5'
*** Redact and save
use "$projectdir/output/tables/cox_model_summary_sens_5", clear
save "$projectdir/output/tables/cox_model_summary_sens_5", replace
export delimited using "$projectdir/output/tables/cox_model_summary_sens_5.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_5", clear
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_sens_5", replace
export delimited using "$projectdir/output/tables/cox_model_rates_sens_5.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_5", clear
foreach var of varlist *events *ptime {
gen `var'_midpoint = (ceil(`var'/6)*6) - (floor(6/2) * (`var'!=0))
}
foreach var in all control sot pax mol {
gen `var'_rate_midpoint = (`var'_events_midpoint/`var'_ptime_midpoint)*1000
gen `var'_lci_midpoint = (invpoisson(`var'_events_midpoint,.975)/`var'_ptime_midpoint)*1000
gen `var'_uci_midpoint = (invpoisson(`var'_events_midpoint,.025)/`var'_ptime_midpoint)*1000
}
keep failure *midpoint
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_round_sens_5", replace
export delimited using "$projectdir/output/tables/cox_model_rates_round_sens_5.csv", replace
*******************************************************************************************************************
** SENSITIVITY ANALYSIS 6 == restricted to covid positive date, eligible and pax contraindicated - start date for treatment is TREAT DATE **
use "$projectdir/output/data/sensitivity_analysis.dta", clear
drop if pre_drug_test>5 & drug>0
tab drug pre_drug_test
tab drug paxlovid_contraindicated
tab drug eligible
*** Hazard of events
tempname cox_model_summary_sens_6
postfile `cox_model_summary_sens_6' str20(model) str20(failure) ///
hr_sot lc_sot uc_sot hr_pax lc_pax uc_pax hr_mol lc_mol uc_mol ///
using "$projectdir/output/tables/cox_model_summary_sens_6", replace
foreach fail in $ae_combined {
stset stop_`fail', id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
foreach model in crude agesex adj{
stcox $`model', vce(robust)
matrix b = r(table)
local hr_sot = b[1,2]
local lc_sot = b[5,2]
local uc_sot = b[6,2]
local hr_pax = b[1,3]
local lc_pax = b[5,3]
local uc_pax = b[6,3]
local hr_mol = b[1,4]
local lc_mol = b[5,4]
local uc_mol = b[6,4]
post `cox_model_summary_sens_6' ("`model'") ("`fail'") (`hr_sot') (`lc_sot') (`uc_sot') (`hr_pax') (`lc_pax') (`uc_pax') (`hr_mol') (`lc_mol') (`uc_mol')
}
}
postclose `cox_model_summary_sens_6'
**** Rates of events
tempname coxoutput_rates_sens_6
postfile `coxoutput_rates_sens_6' str20(failure) ///
all_ptime all_events all_rate all_lci all_uci ///
control_ptime control_events control_rate control_lci_ control_uci ///
sot_ptime sot_events sot_rate sot_lci sot_uci ///
pax_ptime pax_events pax_rate pax_lci pax_uci ///
mol_ptime mol_events mol_rate mol_lci mol_uci ///
using "$projectdir/output/tables/cox_model_rates_sens_6", replace
foreach fail in $ae_disease $ae_disease_serious $ae_combined {
stset stop_`fail' if eligible==1 & paxlovid_contraindicated==0, id(patient_id) origin(time start_date) enter(time start_date) failure(fail_`fail'==1)
stptime
local all_rate = `r(rate)'
local all_ptime = `r(ptime)'
local all_lci = `r(lb)'
local all_uci = `r(ub)'
local all_events = `r(failures)'
stptime if drug == 0
local control_rate = `r(rate)'
local control_ptime = `r(ptime)'
local control_lci = `r(lb)'
local control_uci = `r(ub)'
local control_events = `r(failures)'
display "no drug"
stptime if drug == 1
local sot_rate = `r(rate)'
local sot_ptime = `r(ptime)'
local sot_lci = `r(lb)'
local sot_uci = `r(ub)'
local sot_events = `r(failures)'
display "sotrovimab"
stptime if drug == 2
local pax_rate = `r(rate)'
local pax_ptime = `r(ptime)'
local pax_lci = `r(lb)'
local pax_uci = `r(ub)'
local pax_events = `r(failures)'
display "paxlovid"
stptime if drug == 3
local mol_rate = `r(rate)'
local mol_ptime = `r(ptime)'
local mol_lci = `r(lb)'
local mol_uci = `r(ub)'
local mol_events = `r(failures)'
display "molnupavir"
post `coxoutput_rates_sens_6' ("`fail'") (`all_ptime') (`all_events') (`all_rate') (`all_lci') (`all_uci') ///
(`control_ptime') (`control_events') (`control_rate') (`control_lci') (`control_uci') ///
(`sot_ptime') (`sot_events') (`sot_rate') (`sot_lci') (`sot_uci') ///
(`pax_ptime') (`pax_events') (`pax_rate') (`pax_lci') (`pax_uci') ///
(`mol_ptime') (`mol_events') (`mol_rate') (`mol_lci') (`mol_uci')
}
postclose `coxoutput_rates_sens_6'
*** Redact and save
use "$projectdir/output/tables/cox_model_summary_sens_6", clear
save "$projectdir/output/tables/cox_model_summary_sens_6", replace
export delimited using "$projectdir/output/tables/cox_model_summary_sens_6.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_6", clear
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_sens_6", replace
export delimited using "$projectdir/output/tables/cox_model_rates_sens_6.csv", replace
use "$projectdir/output/tables/cox_model_rates_sens_6", clear
foreach var of varlist *events *ptime {
gen `var'_midpoint = (ceil(`var'/6)*6) - (floor(6/2) * (`var'!=0))
}
foreach var in all control sot pax mol {
gen `var'_rate_midpoint = (`var'_events_midpoint/`var'_ptime_midpoint)*1000
gen `var'_lci_midpoint = (invpoisson(`var'_events_midpoint,.975)/`var'_ptime_midpoint)*1000
gen `var'_uci_midpoint = (invpoisson(`var'_events_midpoint,.025)/`var'_ptime_midpoint)*1000
}
keep failure *midpoint
order failure all* control* sot* pax* mol*
save "$projectdir/output/tables/cox_model_rates_round_sens_6", replace
export delimited using "$projectdir/output/tables/cox_model_rates_round_sens_6.csv", replace
*** Graphs - Survival Risk & Survival Curve
/*foreach fail in $ae_combined {
sts graph, by(drug) tmax(28) ylabel(0(0.25)1) ylabel(,format(%4.3f)) xlabel(0(7)28) risktable(,title(" ")order(1 "Control " 2 "Sotrovimab " 3 "Paxlovid " 4 "Molnupiravir ") ///
size(small)justification(left) rowtitle(,size(small)justification(right))) legend(order(1 "Control" 2 "Sotrovimab" 3 "Paxlovid" 4 "Molnupiravir") symxsize(*0.4) size(small)) ///
xtitle("Analysis time (years)") ylabel(0.9(.025)1) ylabel(,angle(horizontal)) plotregion(color(white)) graphregion(color(white)) ytitle("Survival Probability" ) xtitle("Time (Days)") ///
title ("Kaplan Meier `fail'") saving("$projectdir/output/figures/survrisk_`fail'", replace)
graph export "$projectdir/output/figures/survrisk_`fail'.svg", as(svg) replace
stcurve, survival at1(drug=0) at2(drug=1) at3(drug=2) at4(drug=3) title("") range(0 28) xtitle("Analysis time (years)") legend(order(1 "Control" 2 "Sotrovimab" 3 "Paxlovid" 4 "Molnupiravir") ///
symxsize(*0.4) size(small)) ylabel(,angle(horizontal)) plotregion(color(white)) graphregion(color(white)) ytitle("Survival Probability" ) xtitle("Time (Days)") ///
title ("Survival Curve `fail'") saving("$projectdir/output/figures/survcurve_`fail'", replace)
graph export "$projectdir/output/figures/survcur_`fail'.svg", as(svg) replace
}
*/