Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Put smoothed hazard plots on one graph


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: Put smoothed hazard plots on one graph
Date   Sat, 10 Aug 2013 16:21:17 -0400

Diego:

As you require different -stset- statements, you need different
approaches. Here are examples with two times and two event indicators.
The first example tricks Stata into putting each event into a separate group,
then uses . sts graph, hazard by(event)

In the second approach,  you smooth the hazards yourself and gives you
complete control over each smooth. Choosing the smoothing parameters,
especially the kernel, is a challenge for which I have no good advice.

Steve

*************CODE BEGINS*************
sysuse cancer, clear
/* Create diffeent outcomes */
gen stime1 = studytime
gen stime2 = studytime+10
gen f1 = died
gen f2 = 1- died
tempfile t0 t1 t2
save `t0'

/* Make temporary data set for each outcome */
gen stime = stime1
gen fail = f1
gen event =1
save `t1'

use `t0', clear
gen stime = stime2
gen fail = f2
gen event =2
append using `t1'

stset stime, fail(fail)
sts graph, hazard by(event) kernel(epan) width(8 8)
**************CODE ENDS**************

Smooth yourself:
*************CODE BEGINS*************
/* Separate -stset- */
sysuse cancer, clear
gen stime1 = studytime
gen stime2 = studytime+10
gen f1 = died
gen f2 = 1- died

stset stime1 , fail(f1)
sts gen haz1 = h
gen _t1 = _t

stset stime2, fail(f2 )
gen _t2 = _t
sts gen haz2 = h

lpoly haz1 _t1 ,          ///
degree(0) kernel(epan) bwidth(10)      ///
noscatter   nograph      ///
gen(hs1) at(_t1)
label var hs1 "Event 1"

lpoly haz2 _t2 ,           ///
degree(1) kernel(epan2)  bwidth(15)     ///
  noscatter   nograph    ///
gen( hs2) at(_t2)
label var hs2 "Event 2"

twoway connect hs1 _t1, sort ms(i) || ///
       connect hs2 _t2, sort ms(i)
**************CODE ENDS**************





On Aug 9, 2013, at 11:33 AM, D. Diego Torres wrote:

Hello,

I recently discovered that it's quite easy to put multiple Nelson-Aalen plots onto one graph.  Here's the code I used on the merged data:

stset cum6, id(pubid) f(assoc6==1)
sts gen s6=na
stset cum8, id(pubid) f(assoc8==1)
sts gen s8=na
stset cum4, id(pubid) f(assoc4==1)
sts graph, cumh addplot(line s6 cum6, sort c(J) || line s8 cum8, sort c(J) ///
 ytitle("Cumulative Hazard") ylabel(0(1)3.5) ///
 xtitle("Cumulative Months of FTE Enrollment")  legend(order(1 "Community College" 2 ///
 "Private" 3 "For-Profit"))) saving(AAcumhaz, replace)

Now, in trying to replicate this process for the smoothed hazard, there seems to be a problem with the hazard that -sts gen- is calculating and that gotten from -sts graph, hazard-.

Could someone please help me figure out how to get the smoothed hazard plots onto one graph like I did with the cumulative hazards?

Thanks,
Diego Torres

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index