Announcement

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

  • Getting OS and 95% CI from sts list into KM plot as a text

    Hello all: I need to generate a baseline KM plot for 24 month Survival with a plot of median follow up, 24 mo survival and Median survival data as text. I managed to get Median follow up and Median survival all as macros. But I am having trouble with capturing the 24 month survival data part from sts list. Played with t(max) etc.but it does not help.
    1. How do I capture that in some way and put in the plot as a text? Right now, the figure shows it manually.
    2. Also, the final plot text shows up with a space between "(" and the lower bound value of median follow up $lqrfu even though the code does not indicate so? How do I get rid of that?
    My code is :

    //ST SET FOR 2-year ALL-CAUSE MORTALITY
    * OS24 analysis:
    stset docens, fail(dead) origin(time dodx) ///
    enter(time dodx) ///
    exit(time dodx + 24 * 30.455) ///
    scale(30.455)

    // Grab follow up duration and median follow for KM plot
    qui summ tos, detail
    global medfu: di %5.1f `r(p50)'
    global lqrfu: di %5.1f `r(min)'
    global uqrfu: di %5.1f `r(max)'

    // Grab Median survival and range for KM plot
    qui stci
    global meds: di %5.1f `r(p50)'
    global lbs: di %5.1f `r(lb)'
    global ubs: di %5.1f `r(ub)'

    sts graph, survival ci risktable noshow ///
    graphregion(margin(small) icolor(white) color(white) ) ///
    title("Baseline survival function-Entire Cohort", color(black) size(medsmall)) ///
    xtitle("Time since Diagnosis (months)", size(small)) ///
    xlabel(0(2)25, labs(small)) ylabel(0(0.25)1, angle(0) labs(small)) ///
    ytitle("Proportion surviving", size(small) margin(medium)) ///
    xline(8.2, lcolor(gray%50) lpattern(dot)) ///
    yline(.17, lcolor(gray%50) lpattern(dot)) ///
    ylabel(0 .174 .5 1) ///
    ciopts(lwidth(0)) ///
    legend(off) ///
    text(.75 15 "Median follow up: {bf:$medfu mo} ($lqrfu, $uqrfu mo)" "24mo surv.: {bf:17.4%} (11%-25%)" "Medn. surv.: {bf:$meds mo} ($lbs-$ubs mo)" ///
    ,place(c) nobox just(left) margin(l+1 t+1 b+1) width(65) size(small)) ///
    caption("", span size(vsmall)) ///
    name(Fig_basesurv_km_entcohort, replace)


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int(dodx docensor) long dead
    21348 21798 1
    21916 22125 1
    20301 20444 1
    21829 22099 1
    22095 22171 1
    22287 22667 1
    21366 21544 1
    22203 22509 1
    20328 21806 1
    20816 21205 1
    21962 22162 1
    21279 21314 1
    22530 22658 0
    20508 20601 1
    22517 22760 1
    20171 20377 1
    21360 21442 1
    21455 21901 1
    21334 21715 1
    21780 21920 1
    20040 20930 1
    20969 21010 1
    21335 21553 1
    21992 22078 1
    21511 22123 1
    22285 22368 1
    21500 21734 1
    21856 22885 1
    21419 21609 1
    20159 20464 1
    20433 20580 1
    22655 22741 1
    19540 20939 1
    18226 20612 1
    21124 21729 1
    21082 21353 1
    21719 21973 1
    21304 21403 1
    22434 22496 1
    21105 22890 0
    22977 23071 0
    20468 20806 1
    21738 22977 0
    20789 20885 1
    22140 23062 0
    19991 20907 1
    21797 21806 1
    20083 20116 1
    20109 20541 1
    21931 22424 1
    20137 20673 1
    20137 20946 1
    21531 21829 1
    20280 20868 1
    20285 20334 1
    20293 20698 1
    20270 21455 1
    20558 20667 1
    20887 22427 1
    21850 22133 1
    20362 20399 1
    20419 20534 1
    20458 20518 1
    21342 22437 1
    20578 20739 1
    20671 20721 1
    20773 21273 1
    20773 20852 1
    21601 21634 1
    20816 21047 1
    20850 21043 1
    20885 21139 1
    20730 21948 1
    20936 21397 1
    20969 21267 1
    22910 23030 0
    21062 21111 1
    21173 21267 1
    21158 21203 1
    21249 21428 1
    21249 21595 1
    21922 21962 1
    21271 21588 1
    21293 21713 1
    22811 23064 0
    21346 22359 1
    21093 21443 1
    21798 21901 1
    22404 22488 1
    21764 21841 1
    21411 21543 1
    21567 21974 1
    21444 21608 1
    21850 21933 1
    21626 21740 0
    21651 21817 1
    21366 21948 1
    21759 21791 1
    22271 22894 0
    21900 22027 1
    end
    format %tdnn/dd/CCYY dodx
    format %tdnn/dd/CCYY docensor
    label values dead deadlab
    label def deadlab 0 "Alive", modify
    label def deadlab 1 "Dead", modify
    Click image for larger version

Name:	Fig_basesurv_km_entcohort.png
Views:	2
Size:	66.7 KB
ID:	1704479
    Attached Files

  • #2
    Hi, Girish.

    This is likely to help only partially, but it might be the first step.

    You can run the sts list with the saving option

    Code:
    sts list,    saving(my_results, replace)
    preserve
    use my_results, clear
    local N = _N
    local estimate = survivor[`N']
    local lb = lb[`N']
    local ub = ub[`N']
    restore
    
    dis `estimate'
    dis `lb'
    dis `ub'
    ****** continue to the KM graph

    For the graph, have you tried this?

    Code:
    global meds = round(r(p50),0.01)
    global lbs = round(r(lb),0.01)
    global ubs = round(r(ub),0.01)
    Last edited by Tiago Pereira; 05 Mar 2023, 20:11.

    Comment


    • #3
      Originally posted by Tiago Pereira View Post
      Hi, Girish.

      This is likely to help only partially, but it might be the first step.

      You can run the sts list with the saving option

      Code:
      sts list, saving(my_results, replace)
      preserve
      use my_results, clear
      local N = _N
      local estimate = survivor[`N']
      local lb = lb[`N']
      local ub = ub[`N']
      restore
      
      dis `estimate'
      dis `lb'
      dis `ub'
      ****** continue to the KM graph

      For the graph, have you tried this?

      Code:
      global meds = round(r(p50),0.01)
      global lbs = round(r(lb),0.01)
      global ubs = round(r(ub),0.01)
      That worked perfectly, Tiago. I had not tried the follow up code you suggested. That worked really well too. I am just beginning to use global macros and matrix and learning how things work.

      Comment

      Working...
      X