Announcement

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

  • Add line to sts graph (kaplan meier)

    Im having trouble with overlaying two graphs.


    I have 3208 observations for my survival graph (curve1).
    I have 16 coordinates for curve2
    Code:
     *bagX
    set obs 3224
    gen bagX = .
    replace bagX = 0 if _n == 3209
    replace bagX = 1 if _n == 3210
    replace bagX = 2 if _n == 3211
    replace bagX = 3 if _n == 3212
    replace bagX = 4 if _n == 3213
    replace bagX = 5 if _n == 3214
    replace bagX = 6 if _n == 3215
    replace bagX = 7 if _n == 3216
    replace bagX = 8 if _n == 3217
    replace bagX = 9 if _n == 3218
    replace bagX = 10 if _n == 3219
    replace bagX = 11 if _n == 3220
    replace bagX = 12 if _n == 3221
    replace bagX = 13 if _n == 3222
    replace bagX = 14 if _n == 3223
    replace bagX = 15 if _n == 3224
    
    *bagY
    gen bagY = .
    replace bagY = 100 if bagX == 0
    replace bagY = 96.5 if bagX == 1
    replace bagY = 92.9 if bagX == 2
    replace bagY = 89 if bagX == 3
    replace bagY = 85 if bagX == 4
    replace bagY = 80.8 if bagX == 5
    replace bagY = 76.3 if bagX == 6
    replace bagY = 71.7 if bagX == 7
    replace bagY = 66.9 if bagX == 8
    replace bagY = 62 if bagX == 9
    replace bagY = 57 if bagX == 10
    replace bagY = 52 if bagX == 11
    replace bagY = 46.9 if bagX == 12
    replace bagY = 41.9 if bagX == 13
    replace bagY = 37 if bagX == 14
    replace bagY = 32.3 if bagX == 15
    
    
    sts graph, by(ES2)ylabel(1 "100" .8 "80" .6 "60" .4 "40" .2 "20" .0 "0") ytitle("Mortality") xlabel(0(2.5)15) tmax(15) addplot(line bagY bagX)



    The result is a abnorm graph all over the place.
    What am I missing?
    Last edited by Lytfi Krasniqi; 13 Feb 2020, 06:15.

  • #2
    The -addplot- option amounts to

    Code:
    tw line bagY bagX
    which produces
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	16.2 KB
ID:	1536425




    So with your data example, there is no way to determine what

    The result is a abnorm graph all over the place.
    means. I think the sts graph is therefore important in explaining your problem.

    Comment


    • #3
      The sts graph works fine on its own. When I add addplot(line bagY bagY), the graph from sts graph still work the way it should, but the line is "all over the place" meaning that it swings out of the white area, and swings twice.

      twoway doesn't work when using sts graph, so im looking for another way.. and I can't get addplot to work.
      Here is the code for sts graph:

      Code:
      use "F:\Projekter\FSEID00003877\STATA\MACCE1604_KMK_Efter_de4.dta", clear
      
      gen OPDATO2 = date(OPDATO, "YMD"), after(OPDATO)
      format %td OPDATO2
      
      gen DEATHDATE2 = date(DEATHDATE, "YMD"), after(DEATHDATE)
      format %td DEATHDATE2
      
      gen date_difference = (DEATHDATE2 - OPDATO2)/365.25
      
      replace date_difference = 0.0000001 if date_difference == 0
      
      stset date_difference, failure(ALIVE1_DEAD2==2)
      
      
      ***ES
      gen ES2=.
      replace ES2=1 if EUROSCORE2 < 2
      replace ES2=2 if EUROSCORE2 >= 2
      
      *****
      
      expand 2, gen(dub)
      replace ES2 = 9 if dub == 1     //  EUROSCORE2 in three groups (9 = total)
      
      sts graph, by(ES2)ylabel(1 "100" .8 "80" .6 "60" .4 "40" .2 "20" .0 "0") ytitle("Mortality") xlabel(0(2.5)15) tmax(15)  addplot(line bagY bagX)
      stdescribe
      Last edited by Lytfi Krasniqi; 13 Feb 2020, 11:28.

      Comment


      • #4
        I will need to see your data to be able to find out what is going on. If you are not able to create a reproducible example using one of the Stata datasets (or fake data that you have created), post your real data using dataex or upload it.

        Comment


        • #5
          I'm afraid that it's not possible to upload my data and I'm not able to reproduce an example..
          Is there a way to add the coordinates as a function with a range of 0 to 15 to the sts graph?

          Because the coordinates can be describes as: y=(0.0046x^3)-(0.1602x^2)-(3.1362x)+99.862)

          Comment


          • #6
            For the added plot to fit exactly into the overlaid graph, the ranges of the y axis and x axis should match. It may be just a simple scaling problem, but I cannot help much without a reproducible example.

            Comment


            • #7
              I understand Thank you for your response.

              Comment

              Working...
              X