Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Drawing Kaplan Meier sts graph from exported sts list output

    Hello all,

    I would like to redraw the KM graph which, from the original data, would be generate using:
    Code:
    sts graph, by(group)
    but, instead of using the original survival data, using the output from:
    Code:
    sts list, by(group) saving(sts_list_output)
    The reason for needing to do this is to allow combination of KM graphs from different datasets that cannot be combined at an observation level.

    I would very much appreciate advice on how to do this.

    Thanks,
    Markos

  • #2
    Provide a reproducible example. FAQ Advice #12 for details.

    Comment


    • #3
      to allow combination of KM graphs from different datasets that cannot be combined at an observation level.
      see help graph_combine to combine multiple graphs. (and, if needed; after sts graph describe return the twoway command used)

      Comment


      • #4
        Andrew Musau apologies for the oversight. Here is some example code:
        Code:
        *1. //Use dataset
        sysuse cancer.dta, clear
        
        *2. // Draw graph directly
        sts graph, by(drug)
        
        *3. //Instead, list survivor function
        sts list, by(drug) saving(list_output, replace)
        
        *4. //Now use the saved output file
        use list_output, replace
        
        *5. //How to use this data to generate the same graph as in (2) above ?

        Comment


        • #5
          Code:
          // add the origin
          bys drug (time) : gen n = (_n == 1) + 1 // how many copies of that observation
          expand n, gen(new) // make n copies of each observation,
                             // i.e. make a copy of each first observation,
                             // leave the others as is
          
          // make that new observation the orgin of the curves (1,0)                   
          replace time = 0 if new == 1
          replace survivor = 1 if new == 1                    
          
          // look at the result
          sort drug time
          list drug time survivor new , sepby(drug)
          
          // make the graph (slightly better than sts graph)
          seperate survivor, by(drug) veryshortlabel
          twoway line survivor? time, connect(J..) ///
               title(Kaplan-Meier survival estimates) ///
               legend(subtitle(drug)) ///
               ytitle("estimated survival probability") ///
               ylabel(0(.25)1,format(%9.2f)) ///
               name(newgraph, replace)
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment


          • #6
            Thank you so much Maarten Buis

            Comment

            Working...
            X