-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_get_tchdl_aurum.do
65 lines (51 loc) · 2.38 KB
/
pr_get_tchdl_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
cap prog drop pr_get_tchdl_aurum
program define pr_get_tchdl_aurum
syntax, clinicalfile(string) clinfilenum(string) begin(string) end(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' , nogen keep(match master)
drop if (TC_HDLdate<`begin'-365.25*`runin' | TC_HDLdate>`end') & TC_HDLdate!=.
gsort patid -TC_HDLdate
duplicates drop patid if TC_HDLdate<`begin', force
sort patid TC_HDLdate TC_HDLratio
expand 2 if TC_HDLdate>`begin' & TC_HDLdate!=. & patid[_n]!=patid[_n-1]
sort patid TC_HDLdate
by patid: replace TC_HDLratio=. if _n==1 & TC_HDLdate>`begin'
by patid: replace TC_HDLdate=`begin' if _n==1 & TC_HDLdate>`begin'
end