Announcement

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

  • Overlay 3 kaplan-meier survival graphs from 3 different populations

    Hello,
    I'm doing some cross cohort research on SEP and mortality across 3 different cohorts and would like to overlay them onto one graph. Would anyone have any solutions to this. I have viewed previous threads (https://www.stata.com/statalist/arch.../msg00875.html) although my needs are slightly different and I have had trouble adapting this, and would appreciate any help.

    My cohorts have 3 different ages at follow up (Cohort 1: 70, Cohort 2: 58, and Cohort 3: 43 ) therefore each survival curve would require a different length, and setset. I've stripped the code down to the bare minimum needed to translate what I need:

    Code:
    stset exitdate70, failure(dead70) origin(entrydate) enter(age_26) id(pid) scale(4) if cohort==1 & cc1==1
    
    sts graph if cohort==1 & cc1==1, by(housing) 
                             
    stset exitdate58, failure(dead58) origin(entrydate) enter(age_26) id(pid) scale(4) if cohort==2 & cc2==1 
    
    sts graph if cohort==2 & cc2==1, by(housing)  
    
    stset exitdate43, failure(dead43) origin(entrydate) enter(age_26) id(pid) scale(4) if cohort==3 & cc3==1  
    
    sts graph if cohort==3 & cc3==1, by(housing)
    Thank you.

  • #2
    Maybe you could use to option - separate - to produce, well, separate graphs, or - combine - in order to combine so different graphs. There is also the - addplot - option. That said, without a example of the data, it is hard to come up with the code.
    Best regards,

    Marcos

    Comment


    • #3
      Most of these graphs allow you to save the inputs. As Marcos states, what is key is a data example. Here is one technique using Stata's drug2 data set.

      Code:
      webuse drug2
      *PLOT AND SAVE INPUTS 
      sts graph, by(drug)  outfile(inputs)
      gr save sts1.gph
      *REPLICATE GRAPH
      use inputs, clear
      sort drug _t
      replace survival=1 if _t==0
      tw (line survival _t if !drug, connect(s)) (line survival _t if drug, connect(s)), legend(order(1 "placebo" 2 "drug")) title("My replication of K-M graph")
      gr save sts2.gph
      gr combine sts1.gph sts2.gph

      Click image for larger version

Name:	Graph.png
Views:	1
Size:	71.6 KB
ID:	1522252


      So the key is to have all the inputs in one file and plot using twoway.

      Comment


      • #4
        Hi Andrew and Marcos,
        Thanks for your responses- I should have been more clear, Ideally I would like all three of my cohort's graphs combined into a single graph with the same x and y axis, not side-by-side combined graphs. Unfortuently, I can't share my data as some is protected, I could make a mock example if that is of any help.

        Meg

        Comment


        • #5
          #3 shows you how to replicate the graph produced by Stata. The side-by-side is just a comparison of the Stata sts graph and the replication using twoway. As I said, you need to save all inputs from the 3 graphs into one data set and graph all 3. I do not have time to illustrate this, but if you can create a data example, I can show you how to.
          Last edited by Andrew Musau; 28 Oct 2019, 08:46.

          Comment

          Working...
          X