-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_getlast_tchdlrec_aurum.do
67 lines (53 loc) · 2.5 KB
/
pr_getlast_tchdlrec_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
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
cap prog drop pr_getlast_tchdlrec_aurum
program define pr_getlast_tchdlrec_aurum
syntax, clinicalfile(string) clinfilenum(string) index(string) runin(integer) [cutoff(string)]
if "`cutoff'"=="" {
local cutoff "."
}
preserve
display in red "*******************Observation file number: 1*******************"
use "`clinicalfile'_1" , clear
keep if medcodeid=="279462018" | medcodeid=="458249011" | medcodeid=="259250015" | medcodeid=="8396611000006112"
// these are the codes used in read version (44PG.00, 44lF.00, 44PF.00) + an equivalent EMIS version
// other terms which are similar but not total/serum cholesterol : HDL not included
keep if numunitid=="" | numunitid=="1" | numunitid=="65" | numunitid=="260" | numunitid=="292" | numunitid=="405" | numunitid=="421"
drop if obsdate==.
tempfile tempura
save `tempura' , replace
forvalues n=2/`clinfilenum' {
display in red "*******************Observation file number: `n'*******************"
use "`clinicalfile'_`n'" , clear
keep if medcodeid=="279462018" | medcodeid=="458249011" | medcodeid=="259250015" | medcodeid=="8396611000006112"
// these are the codes used in read version (44PG.00, 44lF.00, 44PF.00) + an equivalent EMIS version
// other terms which are similar but not total/serum cholesterol : HDL not included
keep if numunitid=="" | numunitid=="1" | numunitid=="65" | numunitid=="260" | numunitid=="292" | numunitid=="405" | numunitid=="421"
drop if obsdate==.
append using "`tempura'"
save `tempura' , replace
}
destring value, replace
drop if value>`cutoff'
drop if value==0
rename value TC_HDLratio
rename obsdate TC_HDLdate
drop if TC_HDLdate==.
*HDL:LDL ratios recorded on same date
keep patid TC_HDLratio TC_HDLdate
duplicates drop
duplicates tag patid TC_HDLdate, gen(dup)
drop if dup>0 /*Different lab tests on same day indicative of error?*/
keep patid TC_HDLratio TC_HDLdate
save `tempura' , replace
restore
merge 1:m patid using `tempura' , keep(match master)
sort patid TC_HDLdate
by patid: replace TC_HDLratio=. if _merge==3 & TC_HDLdate>`index' & _n==1
by patid: replace TC_HDLdate=. if _merge==3 & TC_HDLdate>`index' & _n==1
drop if TC_HDLdate>`index' & _merge==3 & TC_HDLdate!=.
by patid: replace TC_HDLratio=. if TC_HDLdate<`index'-365.25*`runin' & _merge==3 & _n==_N
by patid: replace TC_HDLdate=. if TC_HDLdate<`index'-365.25*`runin' & _merge==3 & _n==_N
by patid: drop if TC_HDLdate<`index'-365.25*`runin' & _merge==3
sort patid TC_HDLdate TC_HDLratio
by patid: keep if _n==_N
drop _merge
end