generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
303_cox_models_time_stratified.do
114 lines (85 loc) · 3.01 KB
/
303_cox_models_time_stratified.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
********************************************************************************
*
* Do-file: 202_cox_models.do
*
* Programmed by: John & Alex
*
* Data used: None
*
* Data created: None
*
* Other output: None
*
********************************************************************************
*
* Purpose:
*
* Note:
********************************************************************************
clear
do `c(pwd)'/analysis/global.do
cap log close
log using $outdir/cox_models_time_strat.txt, replace t
tempname measures
postfile `measures' ///
str20(comparator) str20(outcome) str25(analysis) str10(adjustment) str10(time) hr lc uc ///
using $tabfigdir/cox_model_summary_time_strat, replace
foreach an in pneumonia gen_population {
use $outdir/combined_covid_`an'.dta, replace
drop patient_id
gen new_patient_id = _n
global crude i.case
global age_sex i.case i.male age1 age2 age3
global full i.case i.male age1 age2 age3 i.stp i.ethnicity i.imd i.obese4cat_withmiss ///
i.smoke htdiag chronic_respiratory_disease i.asthmacat chronic_cardiac_disease ///
i.diabcat i.cancer_exhaem_cat i.cancer_haem_cat i.reduced_kidney_function_cat2 ///
i.chronic_liver_disease i.dementia i.other_neuro i.organ_transplant i.spleen ///
i.ra_sle_psoriasis i.other_immunosuppression i.hist_dvt i.hist_pe i.hist_stroke i.hist_mi i.hist_aki i.hist_heart_failure
foreach v in stroke dvt pe heart_failure mi aki t2dm {
noi di "Starting analysis for `v' Outcome ..."
preserve
local out `v'_cens_gp
local end_date `v'_cens_gp_end_date
* Apply exclusion for AKI and diabetes outcomes
if "`v'" == "t2dm" {
drop if previous_diabetes == 1
local out `v'
local end_date `v'_end_date
}
if "`v'" == "aki" {
drop if aki_exclusion_flag == 1
local out `v'_cens_gp
local end_date `v'_cens_gp_end_date
}
noi di "$group: stset in `a'"
stset `end_date' , id(new_patient_id) failure(`out') enter(indexdate) origin(indexdate)
* STSPLIT
stsplit time , at(30(30)120)
foreach adjust in full {
if "`adjust'" == "full" & "`v'" == "t2dm" {
* remove diabetes
global full i.case i.male age1 age2 age3 i.stp i.ethnicity i.imd i.obese4cat_withmiss ///
i.smoke htdiag chronic_respiratory_disease i.asthmacat chronic_cardiac_disease ///
i.cancer_exhaem_cat i.cancer_haem_cat i.reduced_kidney_function_cat2 ///
i.chronic_liver_disease i.dementia i.other_neuro i.organ_transplant i.spleen ///
i.ra_sle_psoriasis i.other_immunosuppression i.hist_dvt i.hist_pe i.hist_stroke i.hist_mi i.hist_aki i.hist_heart_failure
}
forvalues t = 0(30)120 {
stcox $`adjust' if time == `t' , vce(robust)
matrix b = r(table)
local hr= b[1,2]
local lc = b[5,2]
local uc = b[6,2]
estat phtest, detail
post `measures' ("`an'") ("`v'") ("`out'") ("`adjust'") ("`t'") ///
(`hr') (`lc') (`uc')
}
}
restore
}
}
postclose `measures'
* Change postfiles to csv
use $tabfigdir/cox_model_summary_time_strat, replace
export delimited using $tabfigdir/cox_model_summary_time_strat.csv, replace
log close