Announcement

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

  • Step function for combined line and stacked area plots for competing risks CI functions in stata

    Hello,
    I need help figuring out how to implement step functions in both line and stacked area plots with the CI step function to graph competing event of death prior to the diagnosis of breast cancer. So far I have been able to set up the plot but without the requisite step function using the Aalen Johansen estimator. What I have discovered is the the "stepwise" or "J " option with the "twoway" or "graph tw" commands works well for the first of the requested CI in the combined line plots for the two CIs(attached as graph) but not at all for area plots (attached as graph 1). I need assistance in figuring this out. Instead of the step the plots have diagonal connections linking the points which makes it incorrect. See the code I am using below and the output. Please note that this possible with SAS but I am facile with it. The dataset is also attached.

    use bccarecurrence.dta , clear
    stset time, failure(status=1)

    sts graph, failure

    stcompet cif=ci, compet1(2)
    gen CI1 = cif if status==1
    gen CI2 = cif if status==2
    gen ci_d=1-CI2

    sort time
    replace CI1=0 if _n==1 & CI1==.
    replace CI2=0 if _n==1 & CI2==.

    replace CI1 = CI1[_n-1] if CI1==.
    replace CI2 = CI2[_n-1] if CI2==.

    label variable CI "CI of death before Breast CA"
    label variable CI1 "CI of Breast CA"

    graph tw line CI CI1 time, connect(J) ylab(0 (0.2) 1) xlab(0 (5) 60) ( for graph)

    graph tw area CI CI1 time, connect(J) ylab(0 (0.2) 1) xlab(0 (5) 60) ( for graph1)


    Thanks
    Attached Files

  • #2
    A few issues about your post.

    1. You use the command stcompet from SSC (you are asked to explain the provenance of user-written commands in the FAQs).
    2. I do not see where the variable CI comes from. I see CI1 and CI2.

    gen CI1 = cif if status==1
    gen CI2 = cif if status==2
    If you help others replicate your problem, you will increase the chances of obtaining useful advice.
    Last edited by Andrew Musau; 03 Oct 2019, 15:18.

    Comment


    • #3
      Hello and thanks for the response.
      I sent in the wrong code for generation of the data that was used to make the plots. See updated version below. I don't understand the first comment. Please clarify.

      clear

      use bccarecurrence.dta, clear
      stset time, failure(status=1)

      sts graph, failure

      stcompet cif=ci, compet1(2)
      gen CI1 = cif if status==1
      gen CI2 = cif if status==2
      gen ci_d=1-CI2

      sort time
      replace CI1=0 if _n==1 & CI1==.
      replace CI2=0 if _n==1 & CI2==.

      replace CI1 = CI1[_n-1] if CI1==.
      replace CI2 = CI2[_n-1] if CI2==.


      label variable CI2 "CI of death before Breast CA"
      label variable CI1 "CI of Breast CA"

      graph tw line CI2 CI1 time, connect(J) ylab(0 (0.2) 1) xlab(0 (5) 60)

      graph tw area CI2 CI1 time, connect(J) ylab(0 (0.2) 1) xlab(0 (5) 60)

      Comment


      • #4
        I don't understand the first comment. Please clarify
        Here is what FAQ 12.1 states

        12.1 What to say about your commands and your problem

        If you are using community-contributed (also known as user-written) commands, explain that and say where they came from: the Stata Journal, SSC, or other archives. This helps (often crucially) in explaining your precise problem, and it alerts readers to commands that may be interesting or useful to them.
        So in your case, you use stcompet from SSC and do not state this when describing your problem.


        graph tw area CI2 CI1 time, connect(J) ylab(0 (0.2) 1) xlab(0 (5) 60)
        The -connect()- option does nothing in the tw area command and is just ignored. If you want jumps, you need to ensure that the last value in a given time period is equal to the first value in the next time period. The implementation is straightforward. Below, I illustrate for "CI2".

        Code:
        *PRESERVE BECAUSE WE ARE MAKING CHANGES TO THE DATA
        preserve
        *IDENTIFY CHANGES IN "CI2" (EQUIVALENT TO CHANGES IN TIME)
        gen tag2= CI2[_n]!=CI2[_n+1]
        *CREATE EXTRA OBSERVATIONS AT THE POINT TIME CHANGES
        expand tag2
        *NOW SPECIFY CONDITION
        replace time=time[_n-1] if tag2
        replace CI2=CI2[_n+1] if tag2
        *GRAPH
        graph tw area CI2 CI1 time, connect(J) ylab(0 (0.2) 1) xlab(0 (5) 60)
        *RESTORE DATA
        restore
        Res.:
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	20.9 KB
ID:	1519465

        Comment


        • #5
          Andrew thanks so much for this explanation.
          This makes sense!

          Comment


          • #6
            I also overlooked one of your comments:

            What I have discovered is the the "stepwise" or "J " option with the "twoway" or "graph tw" commands works well for the first of the requested CI in the combined line plots
            Stata requires you to specify an option for each graph. It is something that I feel lacks in the documentation.

            Code:
            graph tw line CI2 CI1 time, connect(J J) ylab(0 (0.2) 1) xlab(0 (5) 60)

            Comment

            Working...
            X