Announcement

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

  • overlaying kaplan meier curves based on two separate stsets of the data

    Hi,
    I am graphing time to an event based on a) the actual data, and b) theoretical data. I am generating survival curves for both using the stset and sts graph commands. Ideally I would like to overlay the theoretical graph on top of the graph based on the actual data. Despite extensive searches of both the net, and various stata books and manuals, I have not been able to find a solution. Does anyone know of a way to do this, and if so, could you kindly help?

    Many thanks,
    Molly

  • #2
    Welcome to Statalist, Molly!

    stcurve doesn't produce Kaplan-Meier plots.
    stcurve plots the survivor, hazard, or cumulative hazard function after stcox, streg, mestreg, or xtstreg.
    However sts graph does produce KM curves and will overlay curves from different groups. Here I assign the observations in the "real" data set "d1" a group variable equal to 1. Then I create a "theoretical" data set "d2" and assign group =2.I append the two datasets, then stset. If you really need a separate stset command for each data set, then please show us your stset statements. Make sure to put the code between CODE delimiters. How to do ithis is shown in FAQ 12 , which is mandatory reading for new list members.

    Code:
    use http://www.stata-press.com/data/r14/drugtr, clear
    gen group = 1 // real data
    save d1, replace
    
    /* Create "theoretical data set d2 for this example */
    replace group = 2
    replace studytime = studytime + exp(rnormal(0,.5))
    replace  died =  rbinomial(1,.5)
    save d2, replace
    
    use d1, clear
    append using d2
    
    stset studytime, fail(died)
    sts graph, by(group)
    Note that longtime Statalist etiquette is to register with full real names; FAQ 3, explains why and how.
    Last edited by Steve Samuels; 06 Oct 2015, 20:16.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      If there is a different stset statement in each data set, use sts list to generate the two survival curves; then append the two data sets. sts list won't include observations at t = 0, so add one for each group, then plot.
      Code:
      use http://www.stata-press.com/data/r14/drugtr, clear
      stset studytime, fail(died)
      sts gen surv = s  //survival curve
      gen group = 1  // "real"
      save d1, replace
      
      use http://www.stata-press.com/data/r14/drugtr, clear
      replace studytime = studytime + exp(rnormal(0,.5))
      replace  died =  rbinomial(1,.5)
      stset studytime, fail(died)
      sts gen surv= s
      gen group = 2  // "hypothetical"
      save d2, replace
      
      use d1, clear
      append using  d2
      save d3, replace
      
      /* Add points at zero  for graphing*/
      keep in 1/2
      keep group _t  surv
      replace _t = 0
      replace surv = 1
      replace group = _n  // 1 & 2
      append using d3
      
      separate surv, by(group) gen(s)
      sort group _t surv
      scatter s1 s2  _t, c(J J) ms(i i)
      Steve Samuels
      Statistical Consulting
      [email protected]

      Stata 14.2

      Comment


      • #4
        I apologize, Molly: you did say you were using sts graph, but I somehow read "stcurve".


        Steve

        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment


        • #5
          Hi Steve,
          Thanks ever so much for your help with this. I followed your first suggestion and it worked beautifully for all except one graph in the series of vaccinations that I was plotting. I am attaching for your attention the graphs, plotted separately using two distinct STSETs, and then plotted on the same curve, where I have two observations per infant, one based on the real date, and one on the theoretical date. For the actual date, there are about 400 infants who never get vaccinated, but when I plot the actual and theoretical dates on the same plot, this does not seem to be illustrated properly. Rather it looks like timing and uptake of vaccination is better using the actual dates than the theoretical dates. In reality what happens is that fewer babies are vaccinated with an earlier median time to vaccination using the actual date, but uptake is much higher using the theoretical date. This is evident when they are plotted on separate graphs. I copy the syntax for you below. Any idea why this is happening and how I can fix it? Or am I somehow misinterpreting the graph?

          Many thanks and best wishes,
          Molly.

          stset time2vacc, failure(OPV3given==1) id(subjectid) enter(DOB) origin(DOB) exit(time2vacc) time0(DOB) scale(7)
          sts graph, by(actual) failure tmax(52) ylabel(0(0.2)1) ytitle ("Probability of OPV3 vaccination") xtitle ("Age in Weeks") title ("") legend (on)



          Attached Files

          Comment


          • #6
            Molly: Please don't post Word attachments. Attach graphs as ,png attachments. Explained here: http://www.statalist.org/forums/help#stata

            I also echo Steve Samuels' reminder (#2) about using full real names here. Explained here: http://www.statalist.org/forums/help#realnames

            Comment


            • #7
              Hi all,

              I would like to get some help. I am plotting a Kaplan Meier survival curve for some patients with oesophageal cancer. It is easy for me to plot the overall survival curve using the "Sts graph" command. I can also plot the survival curve for the different stages(0,1,2,3) using the "Sts graph, by(stage)" command. I am trying to put the Kaplan Meier survival curves for the overall survival and the survival by stages on the same graph to enable me compare the survival of each stage of disease to overall survival but I do not know how to do this on Stata. I would be grateful to obtain some assistance with this.
              Thanks

              Ike

              Comment


              • #8
                #7 was asked and answered at https://www.statalist.org/forums/for...the-same-graph

                Comment


                • #9
                  Hi molly and Ike, im not sure how to achieve this in stata but i ended up doing it in R for purposes of a paper. I can share that if youd like.

                  Comment

                  Working...
                  X