Announcement

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

  • Ask for Help to Reproduce the Plot of Estimated Hazard Probability by Group in Discrete-Time Survival Analysis

    I am learning how to use Stata to fit discrete-time hazard models with the book "Applied Longitudinal Data Analysis: Modeling Change and Event Occurrence" (Judy D. Singer & John B. Willet; Oxford University Press, 2003). I can't use the Stata code at https://stats.oarc.ucla.edu/stata/ex...-hazard-model/
    to reproduce the graph in the attached as expected.

    The dataset and the code are listed below for reference.
    use https://stats.idre.ucla.edu/stat/sta.../data/firstsex, clear
    clear stset time, failure(event)
    sts generate s = s, by(pt)
    sts generate h = h,by(pt)
    sort time
    graph twoway (line h time if pt == 1) (line h time if pt == 0), legend(pos(5) ring(0) lab(1 "PT=1") lab(2 "PT=0")) xtitle("Grade") /// ytitle("Estimated Hazard Probability")



    Thanks for your help!
    Attached Files
    Last edited by smith Jason; 16 Mar 2022, 14:20.

  • #2
    Further down the page you can see:

    Code:
     
     generate event = ~censor
    Once I included that line before -stset- I was able to reproduce the graph.

    Comment


    • #3
      Thank you, Professor!
      The code was placed in that place is really confusing.

      Comment

      Working...
      X