Announcement

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

  • How to make one sts graph (failure estimates) with two or more categorical variables (3 or more categories)

    Hi STATALIST-users

    I'm trying to make sts graph (failure estimates) with at least two categorical variables, each splitted in 3 categories.
    So far, I can only make one at the time, and I didn't have any chance to combine the graphs in one graph.
    I have tried graph combine (gives 2 graphs next to each other), addplot will not work...
    I have even tried to ask for

    failure by(var1 var2)

    but then I got combinations of these two variables on the plot (9 combinations), which I am not interested in.

    I'm running STATA 13.1 and I'm quite new to STATA and statistics.

    I hope some of you have the solution or good advice!
    Sincerely
    Edina


  • #2
    Saving the K-M estimates and then using Stata graph commands to plot them will hopefully give what you want.

    Here's an example where we have drug (2 categories) and age (3 categories) and we produce a graph with the 5 curves.

    Code:
    webuse drug2b, clear
    xtile agecat = age, nq(3)
    sts gen km_age=s, by(agecat)
    sts gen km_drug=s, by(drug)
    twoway (line km_age _t if agecat==1 , sort connect(stairstep)) ///
    (line km_age _t if agecat==2 , sort connect(stairstep)) ///
    (line km_age _t if agecat==3 , sort connect(stairstep)) ///
    (line km_drug _t if drug==0 , sort connect(stairstep)) ///
    (line km_drug _t if drug==1 , sort connect(stairstep))

    Comment


    • #3
      Dear Paul Dickman

      Thank you for good advice (for some future work)!

      Unfortunately, it does not gives me what I need.
      1. it gives me survival curves. I need failure estimates.
      2. even if I wanted to use survival curves, the curves for var2 are looking as 'up and down stairs-like' lines. strange.
      3. I cannot stratify by 3rd variable (or just did not find out how to do)

      In my previous attempts, I have used sts graph to make a graph for each categorical variable and save them.
      I have hoped that I can combine these 2 graphs to overlay, but I havent find the solution yet.

      Sincerely
      Edina

      Code I have used for graph 1:
      stset outcome if var3==0, failure(C_outcome==0) origin(time 0) exit(time 1097) scale(365.25)
      global obstime 4000
      sts graph if var3 == 0, failure by(var1) tmax( $obstime ) ///
      title ("xxx", size(*0.8) color(black*0.9) place(ne)) ///
      subtitle ("xx", size(*0.8) color(black*0.9) place(sw)) ///
      note ("Log-rank sum test p", place(sw)) ///
      xsize (4.5) ///
      ysize (4.0) ///
      ytitle("Failure estimates" "for outcome", size(medium)) ///
      ylab (0(0.1)0.6) ///
      ylab (0 "0" 0.1 "10" 0.2 "20" 0.3 "30" 0.4 "40" 0.5 "50" 0.6 "60", gmax angle(hori) axis(1)) ///
      xtitle ("Time to event" "(years after randomization)", size(medium) margin(t+1) place(e) justification(right)) ///
      xlab (0 "0" 0.5 "0.5" 1 "1" 1.5 "1.5" 2 "2" 2.5 "2.5" 3 "3") ///
      legend(off) ///
      plotregion( color(white*0.4) icolor(white*0.1) margin(zero)) ///
      graphregion(color(white*0.4) icolor(white*0.1) margin(medium)) ///
      plot1opts (lpattern(dash) lcol(midgreen) lwidth(mediumthick)) ///
      plot2opts (lpattern(dash) lcol(black) lwidth(mediumthick)) ///
      plot3opts(lpattern(dash) lcol(red) lwidth(mediumthick)) ///
      risktable (0(0.5)3, size(*0.8) order(1 "≤ 1" ///
      2 "1-3" ///
      3 "≥ 3")) ///
      saving(g1.gph, replace)
      Last edited by Edina Hadziselimovic; 19 Oct 2019, 08:03.

      Comment


      • #4
        It's still not clear to me what you want to do, but whatever it is I am confident that the combination of -sts generate- to create the estimates and -twoway- to plot them will be able to do it.

        Note that the failure time is just 1 minus the survivor function.

        sts generate supports -if- and by() so should be able to give you what you want.

        It's possible sts graph can do what you want, but -sts generate- will do additional things it can't.

        You'r more like to get help if you follow the advice in the FAQ; if you provide data (either your own with dataex or a public data set) and code to create the two graphs you wish to combine then you'll probably find someone will show you how to create a single graph.

        Comment

        Working...
        X