Announcement

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

  • Kaplan-Meier plot - How to edit the numbers at risk

    Consider this example:

    Code:
    use https://www.stata-press.com/data/r18/drug2, clear
    stset, noshow
    sts graph, failure by(drug) risktable
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	79.9 KB
ID:	1757640


    I have compelling reasons to adjust the number of participants at risk, but I aim to automate this process.

    Do you know of any method to, for instance, triple the numbers at risk without the need for manual adjustments through the graph editor?

  • #2
    Go back to the stset and specify frequency weights.

    Code:
    use https://www.stata-press.com/data/r18/drug2, clear
    gen weight=3
    stset studytime [fw=weight], failure(died)
    sts graph, failure by(drug) risktable
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.6 KB
ID:	1757647

    Comment


    • #3
      Andrew, as always, brilliant solutions! Thank you so much.

      Are you aware if there is a workaround non-integer weights? Some of my analyses involve reducing the numbers at risk, say, by 10 fold.

      Comment


      • #4
        For graphing purposes, specifying pweights seems to work.

        Code:
        use https://www.stata-press.com/data/r18/drug2, clear
        gen weight=.1
        stset studytime [pw=weight], failure(died)
        sts graph, failure by(drug) risktable
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.3 KB
ID:	1757652

        Last edited by Andrew Musau; 02 Jul 2024, 13:30.

        Comment


        • #5
          Thank you so much again, Andrew. Indeed, I tried the option aw, but fw does the job. A million thanks!

          Comment


          • #6
            On a related note, the KMunicate study (https://github.com/tpmorris/kmunicat...ster/README.md) elicited views from a range of stakeholders on how best to present Kaplan-Meier-style data. The Stata implementation of the suggested solution is not automated (to my knowledge) but does suggest a coding approach for non-standard KM plots.

            Comment


            • #7
              Thank you, David! KM plots are always a challenge. I did not know that initiative, but it does look remarkably necessary.
              Last edited by Tiago Pereira; 03 Jul 2024, 15:14.

              Comment

              Working...
              X