Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: -sts gen [newvar] = h- : why do I get monotonous (increasing) hazards?

 From Steve Samuels To statalist@hsphsun2.harvard.edu Subject Re: st: -sts gen [newvar] = h- : why do I get monotonous (increasing) hazards? Date Sun, 11 Jul 2010 11:02:15 -0400

```I haven't tried it, László.     You can, however, choose intervals at
specified end points.  Providing that you have observations at the end
points, you could estimate the "average" hazard in each interval
(a,b], by (cum haz at b   minus cum haz at a)/(b -a).

Here's a version which plots over intervals formed by the observed
times, not fixed intervals. You should be able to take it from here.

Good luck!

Steve
**************************CODE BEGINS**************************
webuse drug2, clear
stset
sts gen, h
sts gen cumhaz = h
sort t
sort _t
gen avhaz = (cumhaz[_n] - cumhaz[_n-1])/(_t[_n] - _t[_n-1]) if _n>1
replace avhaz = cumhaz[1]/_t[1] if _n==1
twoway scatter avhaz _t, c(J)
***************************CODE ENDS***************************

2010/7/11 László Sándor <sandorl@gmail.com>:
> Thanks, Steve.
>
> I thought this was what I was doing. -sts [graph]- shows a smoothed
> density of the deltaH over time. I guess delthaH *is* what I get from
> -sts gen-. So I must be plotting it the wrong way. Could you help me
> have a "step function" (in _t, I guessed) instead of -sts [graph],
> hazard- exactly as a histogram relates to a kernel density estimate?
>
> Thanks again,
>
> Laszlo
>
> On Sun, Jul 11, 2010 at 4:10 PM, Steve Samuels <sjsamuels@gmail.com> wrote:
>>
>> -sts gen-  does not produce estimates of the hazard function.
>>
>> From the help:
>>
>> " h produces the estimated hazard component deltaH_j = H(t_j) -
>> H(t_(j-1)), where t_j is the current failure time and t_(j-1) is the
>> previous one. This is mainly a utility function used to calculate the
>> estimated cumulative hazard H(t_j), yet you can estimate the hazard
>> via a kernel smooth of the deltaH_j..."
>>
>>
>> Steve
>>
>> Steven Samuels
>> sjsamuels@gmail.com
>> 18 Cantine's Island
>> Saugerties NY 12477
>> USA
>> Voice: 845-246-0774
>> Fax:    206-202-4783
>>
>>
>> 2010/7/11 László Sándor <sandorl@gmail.com>:
>> > Ahh, sorry, I forgot the code, though it is nothing surprising, I think:
>> >
>> > sts if clean == 1, hazard by(reviewerrole)  tmax(60) ///
>> >        title("Completion hazards by treatment group") ///
>> >        xline(45) xline(28) xline(21, lc(green)) xline(38, lc(green))
>> > graph export refhazard.pdf, replace
>> >
>> > cap drop hazard
>> > sts generate hazard = h, by(reviewerrole)
>> >
>> > 2010/7/11 László Sándor <sandorl@gmail.com>:
>> >> Hi,
>> >>
>> >> I wanted to use -sts gen- to produce my own variant of the hazard
>> >> graphs that -sts [graph]- produces. I am puzzled by what I get. That
>> >> graph shows (very plausibly for my data) varying hazard, sometimes
>> >> rising, sometimes falling, for all the four groups I plot it
>> >> separately (using the option -by-). When I used the -sts gen [newvar]
>> >> = h- command, I get hazards monotonously increasing in "time" (_t
>> >> after stset).
>> >>
>> >> What am I doing wrong?
>> >>
>> >> I paste you the commands I use, but they are not functional w/o my
>> >> data, I know. In any case, it would very useful if you could help me
>> >> reproduce the -sts graph ..., hazard- graphs using the output of -sts
>> >> gen ...=h-. (FYI, my goal is to use rough step function from -graph
>> >> bar- instead of smooth kernel density estimate.)
>> >>
>> >> Thank you!
>> >>
>> >> Laszlo
>> >> *
>> >> *   For searches and help try:
>> >> *   http://www.stata.com/help.cgi?search
>> >> *   http://www.stata.com/support/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/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/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/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>

--
Steven Samuels
sjsamuels@gmail.com
18 Cantine's Island
Saugerties NY 12477
USA
Voice: 845-246-0774
Fax:    206-202-4783

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