-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloss_analysis3.do
50 lines (35 loc) · 1.43 KB
/
loss_analysis3.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
set li 130
cap log close
log using loss_analysis2.log, replace
noi di "Run by AMM on $S_DATE $S_TIME"
************ create analysis set for loss of all spatypes
noi di "loss of spatypes where gain seen in the study"
use "E:\users\amy.mason\staph_carriage\Datasets\record_per_spa.dta", clear
sort patid this_spa timepoint
* drop all spatypes that are present at timepoint ==0 or timepoint ==2
by patid this_spa: keep if carriage_this_spa[1]==0 & carriage_this_spa[2]==0
assert _N ==8612
* when to start counting
gen spaid = 10*patid+spacount
gsort spaid -carriage_this_spa timepoint
by spaid: gen startevent = timepoint[1] if carriage_this_spa[1]>0
by spaid: drop if carriage_this_spa[1]==0
assert startevent!=.
assert _N==6944
* when event occurs
by spaid: gen confirmed_loss = (carriage_this[_n]==0 & carriage_this[_n+1]==0 & carriage_this[_n-1]>0 ) & _n!=_N & _n!=1
gsort spaid -confirmed_loss timepoint
by spaid: gen firstevent = timepoint[1] if confirmed_loss[1]==1
by spaid: replace firstevent = timepoint[_N] if confirmed_loss[1]==0
assert firstevent!=.
* drop irrelevant records
drop if timepoint > firstevent
drop if timepoint<= startevent
stset timepoint, fail(confirmed_loss) id(spaid) origin(startevent)
assert _st==1
***
noi di "Kaplan-Meier"
sts graph, risktable ci
graph save Graph "E:\users\amy.mason\staph_carriage\Graphs\KM_loss3.gph", replace
graph export "E:\users\amy.mason\staph_carriage\Graphs\KM_loss3.tif", replace
*****