Announcement

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

  • Adding Log-rank test p-value to the Kaplan Meier graph

    Hello everyone,

    I am trying to add Log-rank test p-value to my Kaplan Meier graph, but I cannot find how to do that in Stata. I would really appreciate it if you could help me with this.

    Bests,
    Mina

  • #2
    After creating the graph (e.g., using -sts graph-), click on File/Start Graph Editor in the graph window, which will open up your graph for various kinds of manual changes. (This is often a useful thing to do.) Then, choose Tools/Add Text. This will allow you to create a text box with (say) "Log-Rank p = 0.03", size the font as desired and make whatever other changes you like, and then click/drag the text box to the desired position on your graph. I don't know of a way to do something like this with syntax commands, but perhaps someone else does.

    Comment


    • #3
      twoway options are valid for most standard Stata graphs.

      Code:
      webuse drug2, clear
      sts graph, cumhaz by(drug) text(2 30 "Log-rank p-value=0.003", size(small))
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	56.6 KB
ID:	1569960

      Comment


      • #4
        Thank you so much

        Comment


        • #5
          You can take this a step further to automate the insertion of the p-value instead of having looking it up after you analysis. In this case you have to calculate it as it is not stored by Stata as is in the case of numerous other commands:
          Code:
          webuse drug2, clear
          sts test drug
          di chi2tail(`r(df)',`r(chi2)')
          local a = chi2tail(`r(df)',`r(chi2)')
          local a : di %9.7f `a'
          sts graph, cumhaz by(drug) text(2 30 "Log-rank p-value=`a'", size(small))
          In this case the p-value is very small but you get the idea.

          Comment


          • #6
            Thank you so much Kevin Polkingthorn ! This is exactly what I needed and so I created this account to thank people from the past like you.

            However, to add some substance to this post: You can also make this number a little more 'usable' by rounding it like this when you define the local:

            Code:
            local a = round(chi2tail(`r(df)',`r(chi2)'), 0.001)

            Comment

            Working...
            X