generated from opensafely/research-template
/
400_baseline_characteristics.do
137 lines (111 loc) · 4.54 KB
/
400_baseline_characteristics.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
*an_tablecontent_PublicationDescriptivesTable
*************************************************************************
*Purpose: Create content that is ready to paste into a pre-formatted Word
* shell "Table 1" (main cohort descriptives) for the Risk Factors paper
*
*Requires: final analysis dataset (cr_analysis_dataset.dta)
*
*Coding: Krishnan Bhaskaran
*
*Date drafted: 17/4/2020
*************************************************************************
clear
do `c(pwd)'/analysis/global.do
*******************************************************************************
*Generic code to output one row of table
cap prog drop generaterow
program define generaterow
syntax, variable(varname) condition(string)
*put the varname and condition to left so that alignment can be checked vs shell
file write tablecontent ("`variable'") _tab ("`condition'") _tab
cou
local overalldenom=r(N)
cou if `variable' `condition'
local rowdenom = r(N)
local colpct = 100*(r(N)/`overalldenom')
file write tablecontent (`rowdenom') (" (") %3.1f (`colpct') (")") _n
/*cou if `outcome'==1 & `variable' `condition'
local pct = 100*(r(N)/`rowdenom')
file write tablecontent (r(N)) (" (") %4.2f (`pct') (")") _n*/
end
*******************************************************************************
*Generic code to output one section (varible) within table (calls above)
cap prog drop tabulatevariable
prog define tabulatevariable
syntax, variable(varname) start(real) end(real) [missing]
foreach varlevel of numlist `start'/`end'{
generaterow, variable(`variable') condition("==`varlevel'")
}
if "`missing'"!="" generaterow, variable(`variable') condition(">=.")
end
*******************************************************************************
foreach v in covid covid_community pneumonia {
*Set up output file
cap file close tablecontent
file open tablecontent using $tabfigdir/an_descriptiveTable_`v'.txt, write text replace
use "$outdir/cohort_rates_`v'", clear
gen byte cons=1
tabulatevariable, variable(cons) start(1) end(1)
file write tablecontent _n
tabulatevariable, variable(agegroup) start(1) end(5)
file write tablecontent _n
tabulatevariable, variable(male) start(0) end(1)
file write tablecontent _n
tabulatevariable, variable(ethnicity) start(1) end(5) missing
file write tablecontent _n
tabulatevariable, variable(ethnicity) start(1) end(7)
file write tablecontent _n
/*tabulatevariable, variable(obese4cat) start(1) end(4)
file write tablecontent _n
tabulatevariable, variable(smoke_nomiss) start(1) end(3)
file write tablecontent _n
tabulatevariable, variable(ethnicity) start(1) end(5) missing
file write tablecontent _n
tabulatevariable, variable(imd) start(1) end(5)
file write tablecontent _n _n
*tabulatevariable, variable(bpcat) start(1) end(4) missing
tabulatevariable, variable(htdiag_or_highbp) start(1) end(1)
**COMORBIDITIES
*RESPIRATORY
tabulatevariable, variable(chronic_respiratory_disease) start(1) end(1)
*ASTHMA
tabulatevariable, variable(asthmacat) start(2) end(3) /*no ocs, then with ocs*/
*CARDIAC
tabulatevariable, variable(chronic_cardiac_disease) start(1) end(1)
*DIABETES
tabulatevariable, variable(diabcat) start(2) end(4) /*controlled, then uncontrolled, then missing a1c*/
file write tablecontent _n
*CANCER EX HAEM
tabulatevariable, variable(cancer_exhaem_cat) start(2) end(4) /*<1, 1-4.9, 5+ years ago*/
file write tablecontent _n
*CANCER HAEM
tabulatevariable, variable(cancer_haem_cat) start(2) end(4) /*<1, 1-4.9, 5+ years ago*/
file write tablecontent _n
*REDUCED KIDNEY FUNCTION
tabulatevariable, variable(reduced_kidney_function_cat2) start(2) end(5)
/*DIALYSIS
tabulatevariable, variable(dialysis) start(1) end(1) */
*LIVER
tabulatevariable, variable(chronic_liver_disease) start(1) end(1)
*DEMENTIA
tabulatevariable, variable(stroke_dementia) start(1) end(1)
*OTHER NEURO
tabulatevariable, variable(other_neuro) start(1) end(1)
*ORGAN TRANSPLANT
tabulatevariable, variable(organ_transplant) start(1) end(1)
*SPLEEN
tabulatevariable, variable(spleen) start(1) end(1)
*RA_SLE_PSORIASIS
tabulatevariable, variable(ra_sle_psoriasis) start(1) end(1)
*OTHER IMMUNOSUPPRESSION
tabulatevariable, variable(other_immunosuppression) start(1) end(1)
cou
local denom = r(N)
cou if obese==1
local bmimissing=r(N)
cou if smoke==.
local smokmissing=r(N)
file write tablecontent _n ("*missing BMI included in 'not obese' (n = ") (`bmimissing') (" (") %3.1f (100*`bmimissing'/`denom') ("%); missing smoking included in 'never smoker' (n = ") (`smokmissing') (" (") %3.1f (100*`smokmissing'/`denom') ("%))")
*/
file close tablecontent
}