Announcement

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

  • Cut of survival curve after number of risk drops below a certain number

    Dear Forum members,

    Is there a possibility in STATA to simply cut off survival curves (using the command sts graph) after the "number at risk" drops below a certain number?

    For instance if I start with 1000 cases, I would like to stop the curve when the number at risk drops below 10. I can lookup at what time-point the number at risk drops below 10 and subsequently use the option [tmax(#)] to make a graph until that time-point is reached. However, this is not very practical and I can not use this when I have multiple survival curves in one graph.

    Thanks in advance,

    Stein Janssen

  • #2
    You can use sts generate to calculate the survival function (s) and the number at risk (n). With the connect(J) option you will get a step curve.
    You will need to define the origin of curves (0,1); below I show hos it can be done.

    Code:
    // Define origin of survival curves
    clear
    input drug _t s n
    0 0 1 100
    1 0 1 100
    end
    save origin.dta, replace
    
    webuse drug2.dta, clear
    sts generate s=s , by(drug)
    sts generate n=n , by(drug)
    
    append using origin.dta
    twoway (line s _t if drug==0 & n>9, connect(J) sort) ///
           (line s _t if drug==1 & n>9, connect(J) sort)

    Comment

    Working...
    X