Hi everyone,
I’m trying to replicate lognormal hazard graphs that Stata 12.1 produces in Excel so I can better understand and describe how the covariates affect the shape of the curve. Most of the literature in my field focuses on changes in level, rather than shape. In Stata, I stset the data using a time variable in days, and my failure variable is a one-time occurrence (first rearrest). Here’s an example of what I ran in Stata to look at males in my sample, focusing in on the first month:
streg if male==1 & timedays<30, distribution(lognormal)
stcurve, haz
[See Stata image attached]
Lognormal images.docx
(If it’s helpful, there are approximately 1,000 males in this sample who failed in the timeframe above.) Then, to create the Excel graphs, I’m using the following formula from the Stata pdf documentation (pg 364)…
[See formula in attachment]
…and inserting the unlogged sigma (1.19) and constant (1.83) from output produced by the streg command above to generate the survival estimates (S). Then I’m converting the survival to a cumulative hazard (-LN[S]), and then adjusting the hazard ratios so they aren’t cumulative. Which (zoomed in on the first 30 days) produces:
[See excel image in attachment]
My question is: is it possible to reproduce this graph exactly in Excel so the hazard ratios on the y axes align? And if so, is the error in the formula I used, or is something else going on? I would feel better if I could fully replicate the graph from Stata.
Thank you in advance for any advice! (And I hope the attachment is visible - I was having trouble uploading some of the images as photos, so feel free to let me know of any problems viewing it.)
Megan
I’m trying to replicate lognormal hazard graphs that Stata 12.1 produces in Excel so I can better understand and describe how the covariates affect the shape of the curve. Most of the literature in my field focuses on changes in level, rather than shape. In Stata, I stset the data using a time variable in days, and my failure variable is a one-time occurrence (first rearrest). Here’s an example of what I ran in Stata to look at males in my sample, focusing in on the first month:
streg if male==1 & timedays<30, distribution(lognormal)
stcurve, haz
[See Stata image attached]
Lognormal images.docx
(If it’s helpful, there are approximately 1,000 males in this sample who failed in the timeframe above.) Then, to create the Excel graphs, I’m using the following formula from the Stata pdf documentation (pg 364)…
[See formula in attachment]
…and inserting the unlogged sigma (1.19) and constant (1.83) from output produced by the streg command above to generate the survival estimates (S). Then I’m converting the survival to a cumulative hazard (-LN[S]), and then adjusting the hazard ratios so they aren’t cumulative. Which (zoomed in on the first 30 days) produces:
[See excel image in attachment]
My question is: is it possible to reproduce this graph exactly in Excel so the hazard ratios on the y axes align? And if so, is the error in the formula I used, or is something else going on? I would feel better if I could fully replicate the graph from Stata.
Thank you in advance for any advice! (And I hope the attachment is visible - I was having trouble uploading some of the images as photos, so feel free to let me know of any problems viewing it.)
Megan
Comment