Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: twoway line graph after stcompet by group

From   Steve Samuels <>
Subject   Re: st: twoway line graph after stcompet by group
Date   Tue, 30 Jul 2013 15:17:55 -0400


The trick is to add fake data points before graphin. 
Below, I've also added points at zero, which are also missing.


*************CODE BEGINS*************
webuse hypoxia, clear
stset dftime, failure(failtype==1)
stcompet cuminc = ci, by(disrec) compet1(2)

gen cum = cuminc if failtype==1
separate cum, by(disrec) veryshortlabel

// Get maxima for time & cumulatives
forvalues i = 0/1{
 sum dftime if disrec ==`i', meanonly
 local tmax`i' = r(max)
 sum cum`i', meanonly
 local cmax`i' = r(max)
/* Add 3 fake data points */
set obs 112  // current is 109
replace cum0 = 0 in 110
replace cum1 = 0 in 110
replace _t = 0 in   110
replace cum0 = `cmax0'   in 111
replace  _t = `tmax0'    in 111
replace cum1 = `cmax1'   in 112
replace  _t = `tmax1'    in 112

line cum0 cum1 _t, sort c(J J)
**************CODE ENDS**************

On Jul 30, 2013, at 1:30 AM, Florian Posch wrote:

Dear Statalisters,

I'd kindly appreciate your help regarding an issue with a competing risk analysis:
I want to produce a graph showing the cumulative incidence functions for two groups using stcompet and twoway (accounting for death as a competing risk):

stset time_to_event, fail(outcome=1)
stcompet cuminc_xvar=ci, by(xvar) compet1(2)
separate cuminc_xvar if outcome==1, by(xvar) veryshortlabel
twoway ///
(line cuminc_xvar0 time_to_event, sort c(J)) ///
(line cuminc_xvar1 time_to_event, sort c(J))

Now my problem is that - when graphing the twoway plot - the cumulative incidence functions stop at the last event, but do not continue horizontally to the right of the graph (in parallel to the x-axis) as a stairstep function like in Kaplan-Meier normally does until the end of follow-up. If I produce the analogous graph using the Kaplan-Meier failure estimator followed by twoway line..., the curves continue nicely to the right until the end of follow-up (as expected).
Any suggestions how to fix the cumulative incidence functions so they look analogous to the KM failure functions?

Thx guys,

Florian Posch
Dept. of Hematology
Medical University of Vienna, Austria

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index