## Stata 15 help for tvc_note

```
Title

tvc note -- Splitting the data at failure times to reproduce the results
from stcox with the tvc() option

Description

This entry shows, by an example, an alternative way to produce the
results from stcox with the tvc() option.  We will split the data at
failure times (using stsplit) and generate interaction terms manually.
In general, using tvc() is the most efficient way to fit a model with
time-varying covariates.  However, doing the process manually allows the
use of some extra features.

Remarks

The tvc() option provides a quick and convenient way to model
time-varying covariates.  A new predictor is added to the model for each
variable specified in tvc().  Each new predictor is equivalent to the
product of the corresponding variable with a function of the study time.
We will refer to these new predictors as interaction terms.

The Cox model is fit by evaluating the partial likelihood at each failure
time.  We will need to generate new variables if we want to manually
include the above interaction terms in the model fit.  Because the
interaction terms are a function of the study time, this will require us
to split the dataset at the failure times.

Example

Setup
. webuse drugtr

See the setting for survival data
. stset

Fit a Cox model with the following covariates:  drug, drug as a
time-varying covariate, and age only as a time-varying covariate.  Use
the square of study time in the interaction terms.

. stcox drug, tvc(drug age) texp(_t^2)

Now we'll produce the same results by using stsplit.  This will take four
steps:

1.  Generate a subject identifier variable if we don't already have one.
Make sure to include this variable in the id() option of stset.

. generate id = _n
. streset, id(id)

2.  Use stsplit to split the data at the failure times.

. stsplit, at(failures)

3.  Generate the variables representing the interaction terms.

. generate agetvc = age*(_t^2)
. generate drugtvc = drug*(_t^2)

4.  Fit the Cox model, including the variable drug and the two variables
interacted with the study time.

. stcox drug drugtvc agetvc

```