-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_analysis.do
288 lines (197 loc) · 8.34 KB
/
main_analysis.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
CODE
MAIN ANALYSIS
Timing of blood draws among hospitalized patients:
An evaluation of the electronic health records from a large health care system
Caraballo C, Mahajan S, Krumholz HM, et al.
This .do file uses the special marker **# to facilitate navigation through its contents
*/
u processed_for_analysis,clear
tab four_seven,m
foreach K in four_five five_six six_seven four_seven {
tab `K' race , chi2 col
tab `K' agecat , chi2 col
tab `K' gender if gender!="Unknown", chi2 col
}
********************************************************************************
********************************************************************************
**# Table and timing distribution, denominator is those between 4 and 7
********************************************************************************
********************************************************************************
tabstat timing if four_seven==1, s(p25 p50 p75 mean sd)
tabstat timing if four_seven==1, s(p25 p50 p75 mean sd) by(race)
tabstat timing if four_seven==1, s(p25 p50 p75 mean sd) by(gender)
tabstat timing if four_seven==1, s(p25 p50 p75 mean sd) by(agecat)
kwallis timing if four_seven==1, by(race)
kwallis timing if four_seven==1, by(agecat)
kwallis timing if gender!="Unknown" & four_seven==1, by(gender)
foreach K in four_five five_six six_seven {
tab `K' race if four_seven==1, chi2 col
tab `K' agecat if four_seven==1, chi2 col
tab `K' gender if gender!="Unknown" & four_seven==1, chi2 col
}
tab four_five if four_seven==1
tab five_six if four_seven==1
tab six_seven if four_seven==1
********************************************************************************
********************************************************************************
**# % at the beginning and end of the study
********************************************************************************
********************************************************************************
foreach K in four_seven four_five five_six six_seven {
disp "`K' in Nov 2016, percent of all"
tabstat `K' if monthly==682, s(mean sd sem)
disp "`K' in Oct 2019, percent of all"
tabstat `K' if monthly==717, s(mean sd sem)
}
foreach K in four_five five_six six_seven {
disp "`K' in Nov 2016, percent of 4-7"
tabstat `K' if monthly==682 & four_seven==1, s(mean sd sem)
disp "`K' in Oct 2019, percent of 4-7"
tabstat `K' if monthly==717 & four_seven==1, s(mean sd sem)
}
********************************************************************************
********************************************************************************
**# Trends and change. Denominator: all samples.
********************************************************************************
********************************************************************************
u processed_for_analysis,clear
#delimit ;
collapse (mean) four_seven (semean) four_seven_se=four_seven
(mean) four_five (semean) four_five_se=four_five
(mean) five_six (semean) five_six_se=five_six
(mean) six_seven (semean) six_seven_se=six_seven
, by(monthly)
;
#delimit cr
save file_monthly_rates_all,replace
** trends, ARIMA
u file_monthly_rates_all, clear
tsset monthly
foreach K in four_seven four_five five_six six_seven {
arima `K' monthly, ar(1) nolog
}
** change, proportion of all
u file_monthly_rates_all, clear
keep if inlist(monthly,682,717)
sort monthly
foreach K in four_seven four_five five_six six_seven {
local zcrit=invnorm(.975)
noi disp " ******** diff in `K', proportion of all"
local diff=`K'[2]-`K'[1]
local SE = sqrt(`K'_se[2]^2+`K'_se[1]^2)
local lb=`diff'-`zcrit'*`SE'
local ub=`diff'+`zcrit'*`SE'
local Pval=(2*(1-normal(abs(`diff'/`SE'))))
local Pval=cond(`Pval'<0.001,"<0.001",string(`Pval',"%5.3f"))
noi di "`R'" _col(20) %5.2f `diff'*100 _col(30) "(" %5.2f `lb'*100 "," %5.2f `ub'*100 ")" _col(50) "`Pval'"
}
********************************************************************************
********************************************************************************
**# Trends and change. Denominator: early morning samples
********************************************************************************
********************************************************************************
u processed_for_analysis,clear
keep if four_seven==1
sort monthly
#delimit ;
collapse (mean) four_five (semean) four_five_se=four_five
(mean) five_six (semean) five_six_se=five_six
(mean) six_seven (semean) six_seven_se=six_seven
, by(monthly)
;
#delimit cr
save file_monthly_rates_morning,replace
** trends, ARIMA
u file_monthly_rates_morning, clear
tsset monthly
foreach K in four_five five_six six_seven {
arima `K' monthly, ar(1) nolog
}
**# change, proportion early morning
keep if inlist(monthly,682,717)
foreach K in four_five five_six six_seven {
local zcrit=invnorm(.975)
noi disp " ******** diff in `K', proportion of 4-7"
local diff=`K'[2]-`K'[1]
local SE = sqrt(`K'_se[2]^2+`K'_se[1]^2)
local lb=`diff'-`zcrit'*`SE'
local ub=`diff'+`zcrit'*`SE'
local Pval=(2*(1-normal(abs(`diff'/`SE'))))
local Pval=cond(`Pval'<0.001,"<0.001",string(`Pval',"%5.3f"))
noi di "`R'" _col(20) %5.2f `diff'*100 _col(30) "(" %5.2f `lb'*100 "," %5.2f `ub'*100 ")" _col(50) "`Pval'"
}
log close
********************************************************************************
********************************************************************************
**# FIGURES
********************************************************************************
********************************************************************************
**# Histogram
u processed_for_analysis,clear
#delimit ;
histogram timing,
xlabel(
0 "0:00" 1 "1:00"
2 "2:00" 3 "3:00"
4 "4:00" 5 "5:00"
6 "6:00" 7 "7:00"
8 "8:00" 9 "9:00"
10 "10:00" 11 "11:00"
12 "12:00" 13 "13:00"
14 "14:00" 15 "15:00"
16 "16:00" 17 "17:00"
18 "18:00" 19 "19:00"
20 "20:00" 21 "21:00"
22 "22:00" 23 "23:00",
angle(45)
)
ylabel(0(2)20) percent bin(24) xmtick(##2) xtitle("Time of blood draw")
addlabel addlabopts(mlabangle(h) yvarformat(%2.1f)) ;
graph save timing_distribution.gph,replace ;
#delimit cr
**# morning samples distribution by categories
u processed_for_analysis,clear
keep if four_seven==1
** overall
mylabels 0(10)100, myscale(@/100) local(myla)
graph bar (mean) four_five five_six six_seven , stack ytitle("Proportion of early morning samples") ylabel(`myla') legend(order(1 "4:00 to 4:59" 2 "5:00 to 5:59" 3 "6:00 to 6:59") title("Timing")) blabel(bar, position(inside) format(%4.2f)) xsize(3) ysize(4)
graph save morning_samples_all.gph,replace
**# Figure trends, combined
u processed_for_analysis, clear
collapse (mean) four_five (mean) five_six (mean) six_seven, by(monthly)
#delimit ;
mylabels 0(5)50, myscale(@/100) local(myla);
twoway
(connected four_five monthly)
(connected five_six monthly)
(connected six_seven monthly)
,
xlabel(682 "Nov 2016" 688 "May 2017" 694 "Nov 2017" 700 "May 2018" 706 "Nov 2018" 712 "May 2019" 717 "Oct 2019")
ylabel(`myla')
xtitle("")
ytitle("% of all samples")
legend(order(1 "4:00 to 4:59" 2 "5:00 to 5:59" 3 "6:00 to 6:59") title("Timing") ring(0) pos(1))
;
graph save figure_trends_four_seven_denom_all.gph,replace ;
#delimit cr
u processed_for_analysis, clear
keep if four_seven==1
collapse (mean) four_five (mean) five_six (mean) six_seven, by(monthly)
#delimit ;
mylabels 0(5)50, myscale(@/100) local(myla);
twoway
(connected four_five monthly)
(connected five_six monthly)
(connected six_seven monthly)
,
xlabel(682 "Nov 2016" 688 "May 2017" 694 "Nov 2017" 700 "May 2018" 706 "Nov 2018" 712 "May 2019" 717 "Oct 2019")
ylabel(`myla')
xtitle("")
ytitle("% of early morning samples")
legend(off)
;
graph save figure_trends_four_seven_denom_morning.gph,replace ;
#delimit cr
graph combine figure_trends_four_seven_denom_all.gph figure_trends_four_seven_denom_morning.gph, row(2)
graph save figure_trends_four_seven_combined.gph,replace