Sep 27, 2012

Random graphs (3): Kaplan–Meier plots by subsample

This approach of graphing a Kaplan–Meier survival curve is an alternative to -sts graph-, which does not seem to allow for combining overlaying and separating Kaplan–Meier curves of subgroups.


stset ahm2009_jobsearch, failure(fail) /* Declares survival data */

sts generate surv_sex = s, by(country sex)

/* s refers to Kaplan-Meier product-limit estimate of the survivor function,
   -sts generate- is also able to produce other estimates and their standard
   errors. */

twoway  (line surv_sex _t if sex == 1, sort) ///
        (line surv_sex _t if sex == 2, sort) ///
       , by(country, title("Kaplan–Meier survival estimates") col(3)) ///
         legend(label(1 "Males") label(2 "Females") col(2)) ///
         xtitle("Time in months") ytitle("Survival probability") ///
         xsize(5.5) ysize(10)

/* _t has been created by -stset- and refers to the analysis time when
   record ends. */

/* The default sizes of the available area are -ysize(4)- and -xsize(5.5)-,
   by the way. */