Home  /  Resources & support  /  FAQs  /  Failure time, censoring time, and entry time in the Cox model

Why can’t a subject die at time 0?

Why can’t a subject enter and die at the same time in the Cox model?

Title   Failure time, censoring time, and entry time in the Cox model
Author William Gould, StataCorp

Consider a subject who enters at t0 and dies at t1.

Stata interprets the interval as [t0,t1)—closed on the left, open on the right—or, equivalently, as t such that t0 <= t < t1. By that logic, t0=t1=0 makes no sense because it results in the interval [0,0)—the interval would be 0 <= t < 0.

Mechanically, when events happen at the same time, Stata interprets them as really occurring in the order of failures, censorings, and finally entries. Thus, a subject who entered and died at the same time would first die and then enter the sample.

Solving the problem of subjects who die at time 0 (to fit a Cox model)

What you probably mean by this is that subjects entered at time 0 and then, almost instantly, died. If this is the case, you need to change your death times to 0+epsilon, where epsilon is some small number.

Choose epsilon so that 0+epsilon is less than the time of the first death after time 0. When you fit a Cox model, any value of epsilon that meets that constraint will lead to the same coefficients. However, some predictions and other postestimation results will be affected by the value you choose. For these purposes, you might want the value of epsilon to be very small in comparison to the scale of your data.

Say the earliest failure among those failing after time 0 is time 1. You could type

. replace time = 1e-7 if time==0
. stset ...
. stcox ...

Solving the problem of subjects who enter and die at the same time (to fit a Cox model)

This problem deals with situations where you explicitly specify both the entry and the exit times:

. stset t1, failure(outcome) enter(t0) ...

The solution would be to subtract a small number from t0, for example,

. generate eps = 2*epsfloat()*t0
. replace t0 = t0 - eps
. stset t1, failure(outcome) enter(t0) ...

For estimation purposes, you can subtract any small number eps such as no failures or censoring happen in the interval [t0-eps, t0). For postestimation purposes, you might want a very small number; just make sure that it's not smaller than machine precision.

We shift the entry time back, not the failure time forward. To understand why, let’s say

Subject A enters and dies at 5.
Subject B enters at 0 at dies at 5.

This means that subjects A and B died at the same time. Thus, we must keep them dying at the same time and so shift the entry time of subject A to be just a little before time 5. If we instead shifted subject A’s death time forward a little bit, we would be saying that subject A died after B.

Thinking carefully about censoring and failure times

Stata orders the events occurring at the same time as failures, then censorings, then entries. Think about the following:

Subject C enters at 0, censored at 5.
Subject D enters at 0, fails at 5.

Could subject C have died at time 5? That is, was subject C in the risk pool when D died?
Answer: yes. Here is how it happened:

At time 0:

First, deaths (remove from risk pool): none.
Then, censorings (remove from risk pool): none.
Finally, entries (add to risk pool): C and D.

At time 5:

First, deaths (remove from risk pool): D.
Then, censorings (remove from risk pool): C.
Finally, entries (add to risk pool): none.

Therefore, C was in the risk pool when D died.

Is that what we meant when we wrote that Subject C was censored at 5 and D died at 5? If what you mean is Subject C could not have died at time 5, you need to change Subject C’s censoring time to be 5 minus a little, to make it, say, 4.9.