Quantcast

Stata code for Cox Time Varying regression

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Stata code for Cox Time Varying regression

Julian Chen
This post has NOT been accepted by the mailing list yet.
Dear All:

I am doing a survival anlysis for a patient with maximum of three treatments by using cox time varying
covarites regression model. Here the treatment has two effects. FEi represents the ith treatment effect. But I cannot
code the FEi right

ID: patient
Failure: 1 failure 0 not or censored
Number: times of treatments (0,1,2,3,4)
Time: the whole study time for the patient
D1: the time duration from the study beginning to the 1st treatment
D2: the time duration from the study beginning to the 2nd treatment
D3: the time duration from the study beginning to the 3rd treatment

The origin data is
ID   Failure    Time   Number  T1      T2       T3
73 1 2.5 0 0 0 0
74 1 4 0 0 0 0
75 1 3.75 3 0.25 2 2.25
77 1 3.5 0 0 0 0
79 1 8.5 1 1.75 0 0


####################################################################################
The result I want to get by using Stata Code should be

            ID     Time  _d      _t     _t0   F1   F2   F3
 503.       73     2.5    1     2.5      0    0    0    0  
 504.       74       4    1       4      0    0    0    0  
 505.       75     .25    0     .25      0    0    0    0  
 506.       75       2    0       2    .25    1    0    0  
 507.       75    2.25    0    2.25      2    1    1    0  
 508.       75    3.75    1    3.75   2.25    1    1    1  
 509.       77     3.5    1     3.5      0    0    0    0  
 510.       79    1.75    0    1.75      0    0    0    0  
 511.       79     8.5    1     8.5   1.75    1    0    0
F1, F2 F3 should be zero for 73 74 because their number is 0, representing no treatment for them,
therefore no FE for them.

1) I could not code FE right
2) The Time variable is not listed right. It should be constant but using my code, Time variable
becomes the different of _t-_t0.

################################################################################
I used the code and obtain the result below after using the "List..." commond

stset Time, f(Failure) id(ID)
stsplit F1, at(0) after (_t=T1)
replace F1 = F1 + 1

stsplit F2, at(0) after (_t=T2)
replace F2 = F2 + 1

stsplit F3, at(0) after (_t=T3)
replace F3 = F3 + 1
list ID Time _d _t _t0 F1 F2 F3, clean nol

stcox F1 F2 F3 , nohr
################################################################################
the result is

            ID     Time  _d      _t     _t0   F1   F2   F3
 503.       73     2.5    1     2.5      0    1    1    1  
 504.       74       4    1       4      0    1    1    1  
 505.       75     .25    0     .25      0    0    0    0  
 506.       75       2    0       2    .25    1    0    0  
 507.       75    2.25    0    2.25      2    1    1    0  
 508.       75    3.75    1    3.75   2.25    1    1    1  
 509.       77     3.5    1     3.5      0    1    1    1  
 510.       79    1.75    0    1.75      0    0    1    1  
 511.       79     8.5    1     8.5   1.75    1    1    1

But the F1 F2 and F3 are not the right coded actually. For example, F1, F2 F3 should be 0
not 1 for ID 73 ID74 because they do not have treatments.
For ID 79, only F1 is code 1 after the first treatment and F2 and F3 should be 0 too.
Only ID 75 is right
####################################################################################








Loading...