*! version 1.0 22 Feb 2023

Title

tteir -- Prepare time-to-event data for incidence rates

Syntax

tteir
varname
[,
options]

Mandatory, see stset
failure:(failvar[==numlist]) failure event

Options, see stset
origin(time exp) define when a subject becomes at risk

scale(#) rescale time value

enter(time exp) specify when subject first enters study

exit(time exp) specify when subject exits study

Options, see stsplit
* at(numlist) split records at specified analysis times

* every(#) split records when analysis time is a multiple of #.
When # is set to missing the at(failures) option of the stplit
is used

after(spec) use time since spec for at() or every() rather than time since onset of risk

trim exclude observations outside of range

Options, see collapse
by(varlist) groups over which the generated variables are
to be calculated.
The generated time points from stsplit are added the varlist

Options
nintervals(#) Split event evenly into # intervals

mininterval(#) Suggested number of events in each interval.

noquietly Show output from the used commands in the log

* Either at(numlist) or every(#) is required with stsplit at designated times.

Description

The command tteir is a wrapper for the use of stset,
stsplit, and collapse as described in
sections 4.3 to 4.5 in Royston and Lambert (2011) to prepare time-to-event
datasets for poisson regressions with piecewise constant incidence rates.
A piecewise constant incidence rate for an interval can be interpreted as the
average hazard rate for that same interval.
The main idea is to get a minimal but sufficient dataset for analysis.

Note that using mixed-effects poisson regressions
for the reduced datasets leads to similar point estimates but different
variance estimates compared to
mixed-effects parametric survival models.

Examples

The command tteir generates

`"webuse diet, clear"'

`"tteir dox, failure(fail) origin(time doe) scale(365.25) at(0(2)18)"'

five variables summarizing the original dataset:

`"list, sep(0) noobs"'

The list is a summary of number of events and total follow-up time for
each group.

Instead of the Kaplan-Meyer failure curve,

`"webuse diet, clear"'

`"stset dox, failure(fail) origin(time doe) scale(365.25) id(id)"'

`"sts graph, by(hienergy) failure name(km, replace)"'

one can use the tteir command and the predicted incidence rates
from the post estimation of the poisson regression

`"tteir dox, failure(fail) origin(time doe) scale(365.25) at(0(2)18) by(hienergy)"'

`"qui poisson _x bn._start#i.hienergy, irr exposure(_futm) nocons vce(robust)"'

`"predict ir, ir"'

`"format ir %6.4f"'

to get a piece-wice constant Nelson-Aalen failure curve, i.e., the cummulative incidence
rates

`"generate dt = _stop - _start"'

`"bysort hienergy (_stop): generate cir = 1 - exp(-sum(ir*dt))"'

`"format cir %6.4f"'

The simplest way to compare is to use (if installed) addplot

`"addplot km: (line cir _stop if !hienergy,sort) (line cir _stop if hienergy,sort)"'

To reproduce a cox regression like

`"webuse diet, clear"'

`"stset dox, failure(fail) origin(time doe) scale(365.25) id(id)"'

`"stcox i.hienergy"'

can be done simple by

`"tteir dox, failure(fail) origin(time doe) scale(365.25) every(.) by(hienergy)"'

`"qui poisson _x bn._start i.hienergy, irr exposure(_futm) nocons vce(robust)"'

`"lincom _b[1.hienergy], eform"'

To handle non-proportional hazards or time-dependent effects is simple

`"webuse diet, clear"'

`"generate bmi = weight / height / height * 10000"'

`"egen bmi_grp = cut(bmi), at(15 18.5 25 30 200) label"'

`"tteir dox, failure(fail) origin(time dob) enter(time doe) scale(365.25) id(id) at(30(10)70) by(bmi_grp)"'

`"list, sep(0) noobs"'

`"poisson _x i.bmi_grp#bn._start, irr exposure(_futm) nocons vce(robust)"'

Visualizing the time-dependent effects by BMI groups on CHD

`"quietly margins _start#bmi_grp, predict(ir)"'

`"marginsplot, xtitle(Age (years)) title("") ytitle("Incidence rates and 95% CI")"'

To secure better estimates, it would often be better to chose that
events are evenly distributed into the time intervals.
Here 5 intervals are chosen.

`"webuse diet, clear"'

`"tteir dox, failure(fail) origin(time doe) scale(365.25) nintervals(5)"'

`"list, sep(0) noobs"'

Or one can chose intervals with a minimum number of 20 events in each
interval.

`"webuse diet, clear"'

`"tteir dox, failure(fail) origin(time doe) scale(365.25) mininterval(20)"'

`"list, sep(0) noobs"'

Generated variables

tteir generates the following variables:

Name and description

_start Selected start time values.

_stop Selected stop time values.

_futm Total follow-up time for in the original dataset in the
interval starting at _start and ending at the following _start, _stop.

_total Population size at the start time point _start.
Note that the collapse is made after the stsplit

_x Total number of events in the original dataset in the interval
starting at _start and ending at _stop.

Authors and support

Author:

Niels Henrik Bruun,

Aalborg University Hospital

Support:

niels.henrik.bruun@gmail.com

References

Clayton, D. G., and M. Hills. (1993).
Statistical Models in Epidemiology.
Oxford University Press.

Royston, Patrick & Lambert, Paul. (2011).
Flexible Parametric Survival Analysis Using Stata: Beyond the Cox Model.
Stata Press.