Announcement

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

  • Graph superimposed rather than combined

    from these two (nelson aalen) curves i would like to obtain one panel with the superimposed curves rather than two different panels. Is it possible ?

    stset time, fail(cv==1) id(prog)
    sts graph,na
    graph save 1

    stset time, fail(kidney==1) id(prog)
    sts graph,na
    graph save 2
    graph combine 1.gph 2.gph

  • #2
    The addplot command works with two way plots but unfortunately not with sts graph, but you can easily do this "by hand". Here is an example with two causes of failure like yours

    Code:
    use http://data.princeton.edu/pop509/justices.dta, clear
    
    stset tenure, fail(event==1)
    sts gen na1 = na
    twoway line na1 _t, sort connect(step)
    
    stset tenure, fail(event==2)
    sts gen na2 = na
    addplot: line na2 _t, sort connect(step) legend(order(1 "event==1" 2 "event==2"))
    Click image for larger version

Name:	sf23oct2017.png
Views:	1
Size:	13.6 KB
ID:	1415735

    Comment


    • #3
      German Rodriguez' code does not run in my setup (Stata 15, latest update). I have no command prefix -addplot:-. Perhaps it is a user-written program?

      In any case, it isn't needed here. The code already shows how to save the values to be plotted as variables. After that -graph twoway line- does the trick:

      Code:
      use http://data.princeton.edu/pop509/justices.dta, clear
      
      stset tenure, fail(event==1)
      sts gen na1 = na
      
      stset tenure, fail(event==2)
      sts gen na2 = na
      
      twoway line na1 na2 _t, sort connect(step step)
      produces the same graph.

      Comment


      • #4
        My bad, addplot is a command contributed by Ben Jann from Sj 15-3. I should have said graph addplot, an undocumented command that has been around for a long time. Changing addplot: to graph addplot (mo colon) works fine. I though about Clyde's solution but worried that _t might change between the first and second graph, but I see that is not the case here.

        Comment

        Working...
        X