Announcement

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

  • graph stata HR and tertiles

    Click image for larger version

Name:	graph2.png
Views:	2
Size:	17.9 KB
ID:	1489597
    Good morning,
    I'm trying to make a graph as follows after a cox model but I have never used stata before.

    xi:xtmixed i.tertile_smoke

    my outcome is mortality

    I guess it's very simple for someone who knows how to use stata and graphs.

    Any help?

    Thank you
    Cheng

    Attached Files

  • #2
    Welcome to Statalist. I think that if you're interested in fitting survival models with the Cox regression technique, then stcox would be a better choice than xtmixed. The graph comes easily afterward with the postestimation commands margins and marginsplot. As an illustration, run the following do-file and study the commands and output. (Focus on the commands after the "Begin here" comment; the first part is just to create a fictitious dataset for illustration.)
    Code:
    version 15.1
    
    clear *
    
    set seed `=strreverse("1489595")'
    quietly set obs 100
    
    generate double stress = runiform()
    generate double longevity = -ln(runiform()) / 1 / exp(stress)
    generate byte failure = 1
    
    *
    * Begin here
    *
    // Fitit
    egen byte quartile = cut(stress), group(4)
    label define Quartiles 0 First 1 Second 2 Third 3 Fourth
    label values quartile Quartiles
    
    stset longevity, fail(failure)
    
    stcox i.quartile, nolog
    
    // Graphit
    margins quartile, predict(hr)
    
    marginsplot , title("") ///
        plotopts(lcolor(black) mcolor(black) mfcolor(white)) ///
        ciopts(lcolor(black)) level(50) ///
        ylabel(0(1)3, angle(horizontal) nogrid) ///
        xtitle(Quartile of Stress) ///
        yline(1, lcolor(black) lpattern(dash))
    
    exit
    Be sure to look at the online help files and user's manual entries for the relevant commands that are used above.
    Code:
    help st
    help stset
    help stcox
    help factor variables
    help stcox_postestimation
    help margins
    help marginsplot

    Comment


    • #3
      Joseph Coveney

      Thank you so much +++ for your valuable help! I just wanted to ask something else. Actually, I just want to represent the HR and 95% confidence interval that are given in the stata output for my quartiles

      xi:stcox i.quartile_smoke age sex ...
      I'd like to plot the HR of the fist, 2nd and 3rd and 4th quartile with the 95%CI of the output in stata and margins doesn't allow to do that. I can only have predictions.

      Could you help me with that? Otherwise thanks +++ for your help with the graph

      Thank you again so much +++

      Cheng LY

      Comment


      • #4
        HI Joseph Coveney

        thanks for your help.

        i met the similar question.

        for example:


        when some covariates are included in the stcox model,

        code:

        stcox age sex diabetes i.quartile, nolog
        // Graphit margins quartile, predict(hr)
        marginsplot , title("") /// plotopts(lcolor(black) mcolor(black) mfcolor(white)) /// ciopts(lcolor(black)) level(50) /// ylabel(0(1)3, angle(horizontal) nogrid) /// xtitle(Quartile of Stress) /// yline(1, lcolor(black) lpattern(dash))
        exit but i could not get the right graph. could you help me with that? thank you! JIANBO

        Comment


        • #5
          Joseph Coveney

          Comment

          Working...
          X