Announcement

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

  • plot hazard ratio and confidence intervals

    Good morning,

    I have a basic question. I'm starting with stata running a cox model
    xi:stcox i.tertile_smoke age sex ...
    I'd like to plot the HR of the different tertiles of smoke with the 95% confidence interval as I have in the output of STATA. I tried margins but there are predictive values. I'd like to plot the exact 95% CI that appears in the output of stata for my tertiles of smoke.

    I know it's a very basic thing...but any help would be +++ appreciated !
    thank you a lot!

    Cheng LY

  • #2
    Code:
    sysuse cancer, clear
    stcox i.drug age
    
    // save the hazard ratios and confidence intervals as variables
    matrix res = r(table)'
    svmat res, names(col)
    local vars : rowfullnames res
    tokenize `vars'
    gen vars = _n in 1 / `: word count `vars''
    forvalues i = 1/`: word count `vars'' {
        local lab = `"`lab' `i' "``i''""'
    }
    label define vars `lab'
    label value vars vars
    
    // plot them
    twoway scatter b vars in 1/3, xlab(1/3, val) ytitle(hazard ratio) || ///
           rcap ll ul vars in 1/3 , yline(1) legend(off)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you very much +++ Maarten! I'm going to look at your code.

      Best,

      CLY

      Comment


      • #4
        A bit late, but the xi prefix is not necessary and has not been necessary since at least Stata 12. You can write i. and Stata will recognize it without the prefix, and moreover you won't have all the annoying temporary dummy variables generated in your data.
        Be aware that it can be very hard to answer a question without sample data. You can use the dataex command for this. Type help dataex at the command line.

        When presenting code or results, please use the code delimiters format them. Use the # button on the formatting toolbar, between the " (double quote) and <> buttons.

        Comment


        • #5
          Great! Thank you very much. I will keep it in mind!

          Cheers

          Cheng

          Comment

          Working...
          X