-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_get_ED_aurum.do
34 lines (25 loc) · 1.12 KB
/
pr_get_ED_aurum.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
cap prog drop pr_get_ED_aurum
prog define pr_get_ED_aurum
syntax , clinicalfile(string) clinfilenum(string) therapyfile(string) therapyfilenum(string) begin(string) end(string) runin(integer)
preserve
*first ever diagnosis code
pr_get_bclin_aurum, variable(ED) qof(notqof) clinicalfile(`clinicalfile') clinfilenum(`clinfilenum') begin(`begin') end(`end') runin(`runin')
tempfile b_ED
save `b_ED', replace
restore
*first ever treatment
pr_get_btherapy_aurum, variable(ED_drugs) therapyfile(`therapyfile') therapyfilenum(`therapyfilenum') begin(`begin') end(`end') runin(`runin') time(ever)
append using `b_ED'
*combine results in single set of variables
replace EDdate = ED_drugsdate if EDdate == .
assert EDdate !=.
replace b_ED = b_ED_drugs if b_ED == .
assert b_ED !=.
drop ED_drugs b_ED_drugs
*keep only one record per date
gsort patid EDdate -b_ED
bysort patid EDdate: keep if _n==1
*keep only one result before baseline, which needs to overwrite the expanded baseline results created
by patid: replace b_ED=1 if b_ED[_n-1]==1 & EDdate<=`begin'
duplicates drop patid if EDdate<=`begin', force
end