Announcement

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

  • Problem with labels of number at risk in Kaplan-Meier curves

    I am currently using Stata 18.0 and have a minor issue which I however seem not to be able to resolve. I am using the sts graph command to create Kaplan-Meier curves before. In order to put the legend in the plot I was asked to use e different command. However, using that, the legend in the plot appears with the right labels however the labels of the number at risk below the plot cannot be changed using the graph editor and I do not manage to have the same labels as in the plot. Isch event label appears as ‘event = specific label’. Its only a problem when I want to put the legend in the plot and have to use the “risktable legend” option:

    The old command I used:

    Code:
    tempfile t1 t2
    stset TimetoRecurrence_5y, failure(IS_FU_Recurrence)
    gen event =1
    save d1, replace
    
    stset, clear
    stset TimetoRecurrence_5y, failure(recurrent_cSAH_Recurrence)
    replace event = 2
    save d2, replace
    
    stset , clear
    stset TimetoRecurrence_5y, failure(ICH_FU_Recurrence)
    replace event = 3
    save d3, replace
    
    append using d1
    append using d2
    keep event _*
    
    sts graph , by(event) ylabel(0.5 (.25)1) risktable(,  order(1 "Ischemic stroke" 2 "cSAH" 3 "ICH"))  ysc(reverse)
    The new command Im using:

    Code:
    tempfile t1 t2
    stset TimetoRecurrence_5y, failure(IS_FU_Recurrence)
    gen event =1
    save d1, replace
    
    stset, clear
    stset TimetoRecurrence_5y, failure(recurrent_cSAH_Recurrence)
    replace event = 2
    save d2, replace
    
    stset , clear
    stset TimetoRecurrence_5y, failure(ICH_FU_Recurrence)
    replace event = 3
    save d3, replace
    
    append using d1
    append using d2
    keep event _*
    
    label define eventlab 1 "Ischemic stroke" 2 "cSAH" 3 "ICH"
    label value event eventlab
    
    sts graph , by(event) ylabel(0.5 (.25)1) risktable legend( ring (0) pos (11)  order(1 "Ischemic stroke" 2 "cSAH" 3 "ICH"))  ysc(reverse)
    I attach the two graphs.

    Is there a way to use the risktable legend option but still be able to have the labels of the events of the risk table as a specific label and not as ‘event=xyz’?

    Thank you very much for any help!
    Attached Files

  • #2
    In one case, you have the -order()- suboption within -legend()-, and in the other case, you have this within -risktable()-. You can have both. For your future posts, present a reproducible example as recommended in FAQ Advice #12, as I do below.

    Code:
    webuse drug2, clear
    lab def drug 0 "placebo" 1 "drug"
    lab values drug drug
    levelsof drug, local(drugs)
    local legend
    local j 0
    foreach l of local drugs{
        local ++j
        local legend `" `legend' `j' "`:lab (drug) `l''" "'
    }
    sts graph , by(drug) risktable(, order(`legend')) legend( ring (0) pos (11)  order(`legend'))  ysc(reverse)
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	46.2 KB
ID:	1748470

    Last edited by Andrew Musau; 01 Apr 2024, 11:27.

    Comment


    • #3
      Thanks a lot for your help. This worked very well. I probably didnt really understand what I was telling Stata to do. And apologies. Will try better next time, really tried to follow the rules.

      Comment

      Working...
      X