-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr_get_bclin_aurum.do
70 lines (55 loc) · 2.03 KB
/
pr_get_bclin_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
68
69
70
cap prog drop pr_get_bclin_aurum
capture program drop pr_get_bclin_aurum
prog define pr_get_bclin_aurum
syntax , variable(string) qof(string) clinicalfile(string) clinfilenum(string) begin(string) end(string) runin(integer)
preserve
display in red "*******************Observation file number: 1*******************"
*get all observation events matching code list
if "`qof'" == "qof" {
use "$QRiskCodelistdir\cr_codelist_qof_cod_aurum.dta", clear
keep if variable=="b_`variable'"
}
else {
use "$QRiskCodelistdir\cr_codelist_`variable'_aurum.dta", clear
}
merge 1:m medcodeid using "`clinicalfile'_1", nogen keep(match) keepusing(patid obsdate)
gen b_`variable'=1
keep patid obsdate b_`variable'
drop if obsdate==.
tempfile bclin
save `bclin' , replace
forvalues n=2/`clinfilenum' {
display in red "*******************Observation file number: `n'*******************"
if "`qof'" == "qof" {
use "$QRiskCodelistdir\cr_codelist_qof_cod_aurum.dta", clear
keep if variable=="b_`variable'"
}
else {
use "$QRiskCodelistdir\cr_codelist_`variable'_aurum.dta", clear
}
merge 1:m medcodeid using "`clinicalfile'_`n'", nogen keep(match) keepusing(patid obsdate)
gen b_`variable'=1
keep patid obsdate b_`variable'
drop if obsdate==.
append using "`bclin'"
save `bclin' , replace
}
*merge with patient file
restore
merge 1:m patid using `bclin', keep(match master)
*keep first event within specified time table
drop if _merge==3 & obsdate>`end'
drop if _merge==3 & obsdate<`begin'-365.25*`runin'
gsort patid -obsdate
duplicates drop patid if obsdate<`begin' & _merge==3 , force
sort patid obsdate
by patid: keep if _n==1
replace b_`variable'=0 if b_`variable'==.
*add record for unexposed time between start of follow-up and first event
expand 2 if obsdate>`begin' & obsdate!=. & patid[_n]!=patid[_n-1]
sort patid obsdate
by patid: replace b_`variable'=0 if _n==1 & obsdate>`begin'
by patid: replace obsdate = `begin' if _n==1 & obsdate>`begin'
drop _merge
rename obsdate `variable'date
end