generated from opensafely/research-template
/
07b_eth_sensanalysis_nostp_eth5.do
174 lines (141 loc) · 5.69 KB
/
07b_eth_sensanalysis_nostp_eth5.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
/*==============================================================================
DO FILE NAME: 07b_eth_sensanalysis_nostp_eth5
PROJECT: Ethnicity and COVID
AUTHOR: R Mathur (modified from A wong and A Schultze)
DATE: 15 July 2020
DESCRIPTION OF FILE: program 06
univariable regression
multivariable regression
DATASETS USED: data in memory ($tempdir/analysis_dataset_STSET_outcome)
DATASETS CREATED: none
OTHER OUTPUT: logfiles, printed to folder analysis/$logdir
table2, printed to $Tabfigdir
complete case analysis
==============================================================================*/
sysdir set PLUS ./analysis/adofiles
adopath + ./analysis/adofiles
sysdir
global outcomes "tested positivetest icu hes onscoviddeath ons_noncoviddeath onsdeath"
* Open a log file
cap log close
macro drop hr
log using ./logs/07b_eth_sensanalysis_nostp_eth5.log, replace t
cap file close tablecontent
file open tablecontent using ./output/sens_nostp_eth5.txt, write text replace
file write tablecontent ("Table 2: Association between ethnicity in 16 categories and COVID-19 outcomes - no STP") _n
file write tablecontent _tab ("Denominator") _tab ("Event") _tab ("Total person-weeks") _tab ("Rate per 1,000") _tab ("with stp") _tab _tab ("without stp") _tab _tab _n
file write tablecontent _tab _tab _tab _tab _tab ("HR") _tab ("95% CI") _tab ("HR") _tab ("95% CI") _tab _tab _n
foreach i of global outcomes {
di "`i'"
* Open Stata dataset
use ./output/analysis_dataset_STSET_`i'.dta, clear
drop if carehome==1
/* Main Model=================================================================*/
* with strata
stcox i.eth5 i.male age1 age2 age3 i.imd ///
i.bmicat_sa i.hba1ccat ///
gp_consult_count ///
i.smoke_nomiss ///
i.hypertension i.bp_cat ///
i.asthma ///
i.chronic_respiratory_disease ///
i.chronic_cardiac_disease ///
i.dm_type ///
i.cancer ///
i.chronic_liver_disease ///
i.stroke ///
i.dementia ///
i.other_neuro ///
i.egfr60 ///
i.esrf ///
i.immunosuppressed ///
i.ra_sle_psoriasis ///
i.hh_total_cat, strata(stp) nolog
estimates save ./output/modela_`i'_eth5, replace
eststo modela
parmest, label eform format(estimate p lb ub) saving(./output/modela_`i'_eth5, replace) idstr(modela_`i'_eth5)
local hr "`hr' ./output/modela_`i'_eth5 "
* without strata
stcox i.eth5 i.male age1 age2 age3 i.imd ///
i.bmicat_sa i.hba1ccat ///
gp_consult_count ///
i.smoke_nomiss ///
i.hypertension i.bp_cat ///
i.asthma ///
i.chronic_respiratory_disease ///
i.chronic_cardiac_disease ///
i.dm_type ///
i.cancer ///
i.chronic_liver_disease ///
i.stroke ///
i.dementia ///
i.other_neuro ///
i.egfr60 ///
i.esrf ///
i.immunosuppressed ///
i.ra_sle_psoriasis ///
i.hh_total_cat, nolog
estimates save ./output/modelb_`i'_eth5, replace
eststo modelb
parmest, label eform format(estimate p lb ub) saving(./output/modelb_`i'_eth5, replace) idstr(modelb_`i'_eth5)
local hr "`hr' ./output/modelb_`i'_eth5 "
/* Estout================================================================*/
esttab modela modelb using ./output/estout_sens_nostp_eth5.txt, b(a2) ci(2) label wide compress eform ///
title ("`i'") ///
varlabels(`e(labels)') ///
stats(N_sub) ///
append
eststo clear
/* Print table================================================================*/
* Print the results for the main model
* Column headings
file write tablecontent ("`i'") _n
* eth5 labelled columns
local lab1: label eth5 1
local lab2: label eth5 2
local lab3: label eth5 3
local lab4: label eth5 4
local lab5: label eth5 5
local lab6: label eth5 6
/* counts */
* First row, eth5 = 1 (White British) reference cat
qui safecount if eth5==1
local denominator = r(N)
qui safecount if eth5 == 1 & `i' == 1
local event = r(N)
bysort eth5: egen total_follow_up = total(_t)
qui su total_follow_up if eth5 == 1
local person_week = r(mean)/7
local rate = 1000*(`event'/`person_week')
file write tablecontent ("`lab1'") _tab (`denominator') _tab (`event') _tab %10.0f (`person_week') _tab %3.2f (`rate') _tab
file write tablecontent ("1.00") _tab _tab ("1.00") _tab _tab ("1.00") _tab _tab ("1.00") _tab _tab ("1.00") _n
* Subsequent ethnic groups
forvalues eth=2/6 {
qui safecount if eth5==`eth'
local denominator = r(N)
qui safecount if eth5 == `eth' & `i' == 1
local event = r(N)
qui su total_follow_up if eth5 == `eth'
local person_week = r(mean)/7
local rate = 1000*(`event'/`person_week')
file write tablecontent ("`lab`eth''") _tab (`denominator') _tab (`event') _tab %10.0f (`person_week') _tab %3.2f (`rate') _tab
cap estimates use ./output/modela_`i'_eth5
cap lincom `eth'.eth5, eform
file write tablecontent %4.2f (r(estimate)) _tab ("(") %4.2f (r(lb)) (" - ") %4.2f (r(ub)) (")") _tab
cap estimates clear
cap estimates use ./output/modelb_`i'_eth5
cap lincom `eth'.eth5, eform
file write tablecontent %4.2f (r(estimate)) _tab ("(") %4.2f (r(lb)) (" - ") %4.2f (r(ub)) (")") _n
} //end ethnic group
} //end outcomes
file close tablecontent
************************************************create forestplot dataset
dsconcat `hr'
duplicates drop
split idstr, p(_)
ren idstr1 model
ren idstr2 outcome
drop idstr idstr3
tab model
*save dataset for later
outsheet using ./output/FP_sens_nostp_eth5.txt, replace