generated from opensafely/research-template
/
08b_eth_an_infectedpop_eth5_nocarehomes.do
231 lines (179 loc) · 7.89 KB
/
08b_eth_an_infectedpop_eth5_nocarehomes.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
/*=============================================================================
DO FILE NAME: 08b_eth_an_infectedpop_eth5
PROJECT: Ethnicity and COVID
AUTHOR: R Mathur (modified from A wong and A Schultze)
DATE: 15 July 2020
DESCRIPTION OF FILE: Risk of test positive in people receiving a test
univariable regression
multivariable regression
DATASETS USED: data in memory ($output/analysis_dataset)
DATASETS CREATED: none
OTHER OUTPUT: logfiles, printed to folder analysis/$logs
table2, printed to analysis/$outdir
==============================================================================*/
global outcomes "hes icu onscoviddeath ons_noncoviddeath onsdeath"
sysdir set PLUS ./analysis/adofiles
adopath + ./analysis/adofiles
sysdir
* Open a log file
cap log close
log using ./logs/08b_eth_an_infectedpop_eth5.log, replace t
cap file close tablecontent
file open tablecontent using ./output/table4_infectedpop_eth5_nocarehomes.txt, write text replace
file write tablecontent ("Table 4: Odds of each outcome amongst those testing positive - No care homes wave 2") _n
file write tablecontent _tab ("Denominator") _tab ("Event") _tab ("%") _tab ("Crude") _tab _tab ("Age/Sex Adjusted") _tab _tab ("Age/Sex/IMD Adjusted") _tab _tab ("plus co-morbidities") _tab _tab ("plus hh size") _n
file write tablecontent _tab _tab _tab _tab ("OR") _tab ("95% CI") _tab ("OR") _tab ("95% CI") _tab ("OR") _tab ("95% CI") _tab ("OR") _tab ("95% CI") _tab ("95% CI") _tab ("95% CI") _n
foreach i of global outcomes {
* Open Stata dataset
use ./output/analysis_dataset.dta, clear
safecount
*define population as anyone who has received a test
keep if positivetest==1
safecount
keep if carehome==0
safecount
/* keep those with at least 30 days f-up prior to censoring date for each outcome =======================================================*/
drop if `i'_censor_date - positivetest_date <30
/* Create outcomes to be within 30 days of positivetest =======================================================*/
gen `i'_30=0
replace `i'_30=1 if (`i'_date - positivetest_date) <=30 & `i'_date <= stime_`i'
tab `i' `i'_30
/* Sense check outcomes=======================================================*/
safetab positivetest `i'_30
safetab eth5 `i'_30, missing row
/* Main Model=================================================================*/
/* Univariable model */
cap logistic `i'_30 i.eth5 i.stp, nolog
cap estimates save ./output/crude_`i'_eth5, replace
cap parmest, label eform format(estimate p lb ub) saving(./output/crude_`i'_eth5, replace) idstr("crude_`i'_eth5")
cap eststo model1
local hr "`hr' ./output/crude_`i'_eth5 "
/* Multivariable models */
*Age Gender
cap logistic `i'_30 i.eth5 i.male age1 age2 age3 i.stp, nolog
cap estimates save ./output/model0_`i'_eth5, replace
cap parmest, label eform format(estimate p lb ub) saving(./output/model0_`i'_eth5, replace) idstr("model0_`i'_eth5")
cap eststo model2
local hr "`hr' ./output/model0_`i'_eth5 "
* Age, Gender, IMD
cap logistic `i'_30 i.eth5 i.male age1 age2 age3 i.imd i.stp , nolog
cap estimates save ./output/model1_`i'_eth5, replace
cap parmest, label eform format(estimate p lb ub) saving(./output/model1_`i'_eth5, replace) idstr("model1_`i'_eth5")
cap eststo model3
local hr "`hr' ./output/model1_`i'_eth5 "
* Age, Gender, IMD and Comorbidities
cap logistic `i' 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. stp, nolog
cap estimates save ./output/model2_`i'_eth5, replace
cap parmest, label eform format(estimate p lb ub) saving(./output/model2_`i'_eth5, replace) idstr("model2_`i'_eth5")
cap eststo model4
local hr "`hr' ./output/model2_`i'_eth5 "
* Age, Gender, IMD and Comorbidities and household size
cap logistic `i'_30 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 i.stp, nolog
cap estimates save ./output/model3_`i'_eth5, replace
cap parmest, label eform format(estimate p lb ub) saving(./output/model3_`i'_eth5, replace) idstr("model3_`i'_eth5")
cap eststo model5
local hr "`hr' ./output/model3_`i'_eth5 "
/* Estout================================================================*/
cap esttab model1 model2 model3 model4 model5 using ./output/estout_table4_infectedpop_eth5_nocarehomes.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) reference cat
qui safecount if eth5==1
local denominator = r(N)
qui safecount if eth5 == 1 & `i' == 1
local event = r(N)
local pct =(`event'/`denominator')
file write tablecontent ("`lab1'") _tab (`denominator') _tab (`event') _tab %3.2f (`pct') _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)
local pct =(`event'/`denominator')
file write tablecontent ("`lab`eth''") _tab (`denominator') _tab (`event') _tab %3.2f (`pct') _tab
cap estimates use ./output/crude_`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/model0_`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/model1_`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/model2_`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/model3_`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
cap dsconcat `hr'
cap duplicates drop
cap split idstr, p(_)
cap ren idstr1 model
cap ren idstr2 outcome
cap drop idstr idstr3
cap tab model
*save dataset for later
cap outsheet using ./output/FP_infectedpop_eth5.txt, replace
* Close log file
log close