generated from opensafely/research-template
/
AAR001_2_cox_regression.do
114 lines (88 loc) · 2.48 KB
/
AAR001_2_cox_regression.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: AAR001_2_cox_regression.do
*
* Programmed by: Fizz & Krishnan & John
*
* Data used: analysis/
* data_aranalysis_cohort1.dta
* data_aranalysis_cohort2.dta
*
* Data created: None
*
* Other output: Log file: logs/AAR001_2_cox_regression.log
* Estimates: output/
* hr_covidadmission_wave2_male0.txt
* hr_covidadmission_wave2_male1.txt
*
********************************************************************************
*
* Purpose: This do-file fits a multivariable Cox model for the
* absolute risks work and tabulates estimated hazard ratios.
*
********************************************************************************
* Set wave (1 or 2), outcome (coviddeath, covidadmission or composite)
local i = 2
local out = "covidadmission"
clear all
set more off
* Open a log file
cap log close
log using "logs/AAR001_2_cox_regression", replace t
* Open dataset (complete case ethnicity)
use "analysis/data_aranalysis_cohort`i'.dta", clear
drop if ethnicity_5>=.
* Keep under 50s only
drop if age>=50
/* Declare data to be survival */
stset stime_`out'`i', fail(`out'`i') scale(365.25)
/* Fit Cox models */
forvalues j = 0 (1) 1 {
capture erase coefs_cox_2_`j'.ster
stcox age1 age2 age3 ///
ib2.obesecat ///
i.smoke_nomiss ///
i.ethnicity_5 ///
i.imd ///
i.respiratory ///
i.cf ///
i.asthmacat ///
i.cardiac ///
i.hypertension ///
i.diabcat ///
i.af ///
i.dvt_pe ///
i.pad ///
i.cancerExhaem ///
i.cancerHaem ///
i.liver ///
i.stroke ///
i.dementia ///
i.tia ///
i.neuro ///
i.kidneyfn ///
i.transplant ///
i.dialysis ///
i.spleen ///
i.autoimmune ///
i.ibd ///
i.immunosuppression ///
i.smi ///
i.ds ///
i.ldr ///
i.fracture ///
if male==`j' ///
, strata(stp)
estimates save coefs_cox_2_`j', replace
}
*********************************************
* Read in estimates and format for tables *
*********************************************
* Read in programs to format output
qui do "analysis/000_HR_table.do"
forvalues j = 0 (1) 1 {
* Cox model
crtablehr, estimates(coefs_cox_2_`j') ///
outputfile(output/hr_`out'_wave`i'_male`j'.txt)
}
log close