Announcement

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

  • Overlying 3 sts graphs of different outcomes with different FU time

    Hi there,

    I am trying to put three sts graphs into one. There are three different events at follow-up I am interested in, which can be at different time points. I get the survival curves for each event:
    Event 1:
    Code:
    stset TimetoICH_or_FU_years, failure 
    sts graph
    Event 2:
    Code:
    stset TimetoIS_or_FU_years, failure(IS_FU)
    sts graph
    Event3:
    Code:
    stset TimetoreccSAH_or_FU_years, failure(recurrent_cSAH) 
    sts graph
    This gives me three separate KM curves. I would like to get these exact curves all into one graph, not changing/combining anything and if possible labelling them accordingly (ICH on FU, IS on FU and recurrent cSAH on FU). As the event times differ the three time variable cannot be combined. I have checked previous posts and have tried different things including addplot, which didnt work.I have tried using something along the lines of the following posts:
    https://www.statalist.org/forums/for...ts-of-the-data
    and
    https://www.statalist.org/forums/for...-than-combined

    I am using stata 15.1.

    Thank you very much for any suggestions.

    Best,

    Isabel

  • #2
    You tell us little about your data, so I'm assuming that all these statements were run on the same data set--i.e. that people were at risk for multiple events. If not, the modifications needed for the code below should be obvious.
    Code:
    tempfile t1 t2
    stset TimetoICH_or_FU_years, failure(??)
    gen event =1
    save `t1', replace
    
    stset, clear
    stset TimetoIS_or_FU_years, failure(IS_FU)
    replace event = 2
    save `t2', replace
    
    stset , clear
    stset TimetoreccSAH_or_FU_years, failure(recurrent_cSAH)
    replace event = 3
    
    append using `t1'
    append using `t2'
    keep event _*  // _* are the variables created by stset
    sts graph, by(event)
    As FAQ 12 states, saying that something "didn't work" is not helpful. Please in future posts, show what didn't work and provide a sample of data if necessary for us to understand what you are dealing with.
    Last edited by Steve Samuels; 04 Jul 2018, 11:02.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment


    • #3
      Apologies, of course I can provide more informations. Everything was ran on the same data set and yes they are at risk for multiple/different events. We were interested in three outcomes=events: ICH=intracerebral haemorrhgae, IS=ischaemic stroke and recurrent cSAH= convexity subarachnoid haemorrhage
      I have used:

      Code:
      tempfile t1 t2
      stset TimetoICH_or_FU_years, failure(ICH_FU)
      gen event =1
      save d1, replace
      
      stset, clear
      stset TimetoIS_or_FU_years, failure(IS_FU)
      replace event = 2
      save d2, replace
      
      stset , clear
      stset TimetoreccSAH_or_FU_years, failure(recurrent_cSAH)
      replace event = 3
      
      append using d1
      append using d2
      keep event _*                                           
      sts graph, by(event)
      And it worked very well, as attached. Again, apologies, will include more details on what exactly didnt work next time. Just in case its still of matter: used the following:
      Code:
      use *yourfile
      stset TimetoICH_or_FU_years, failure(ICH_FU)
      sts gen surv = s  
      gen group = 1 
      save d1, replace
      
      use *yourfile
      stset TimetoIS_or_FU_years, failure(IS_FU)    
      sts gen surv = s  
      gen group = 2 
      save d2, replace
      
      use *yourfile
      stset TimetoreccSAH_or_FU_years, failure(recurrent_cSAH)    
      sts gen surv = s  
      gen group = 3 
      save d3, replace
      
      use d1, clear
      append using  d2
      save d4, replace
      append using d3
      save d5, replace
      
      keep in 1/2
      keep group _t  surv
      replace _t = 0
      replace surv = 1
      replace group = _n 
      append using d5
      
      separate surv, by(group) gen(s)
      sort group _t surv
      scatter d1 d2  d3 d4, c(J J) ms(i i)
      If I replace the last line by
      Code:
      sts graph, by (group)
      , it again works like you suggested yo I dont need this bit I suppose at all:

      Code:
       keep in 1/2
      keep group _t  surv
      replace _t = 0
      replace surv = 1
      replace group = _n 
      append using d5
      
      separate surv, by(group) gen(s)
      sort group _t surv
      Attached Files

      Comment

      Working...
      X