-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_getlast_fhcvd60_aurum.do
48 lines (36 loc) · 1.28 KB
/
pr_getlast_fhcvd60_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
cap prog drop pr_getlast_fhcvd60_aurum
program define pr_getlast_fhcvd60_aurum
syntax, clinicalfile(string) clinfilenum(string) index(string) runin(integer)
preserve
display in red "*******************Observation file number: 1*******************"
use "`clinicalfile'_1", clear
keep patid medcodeid obsdate
merge m:1 medcodeid using "$QRiskCodelistdir\cr_codelist_fhcvd60_aurum", keep(match) nogen
drop if obsdate==.
rename obsdate fh_date
keep fh_date patid
tempfile tempura
save `tempura', replace
forvalues n=2/`clinfilenum' {
display in red "*******************Observation file number: `n'*******************"
use "`clinicalfile'_`n'", clear
keep patid medcodeid obsdate
merge m:1 medcodeid using "$QRiskCodelistdir\cr_codelist_fhcvd60_aurum", keep(match) nogen
drop if obsdate==.
rename obsdate fh_date
keep fh_date patid
append using "`tempura'"
save `tempura', replace
}
restore
merge 1:m patid using `tempura', keep(match master)
gen before=1 if fh_date>`index' & _merge==3 & fh_date!=.
sort patid before fh_date
by patid: keep if _n==_N
replace fh_date=. if fh_date>`index'
replace fh_date=. if fh_date<`index'-365.25*`runin'
drop _merge before
gen fh_cvd=1 if fh_date!=.
replace fh_cvd=0 if fh_cvd==.
replace fh_date=. if fh_cvd==0
end