Tutorials › Marginal Structural Models › From Longitudinal Records to Survival Person-Periods

Fitting MSMs for Survival Outcomes · Tutorial 163 of 501

From Longitudinal Records to Survival Person-Periods

You will learn to construct and verify start-stop survival records that preserve each person’s observed follow-up, treatment history, and event status.

Advanced 13 min read

What You'll Learn

  • Define start-stop intervals from each person’s observed follow-up and history-update times.
  • Assign one event indicator to the interval ending at an observed event.
  • Handle treatment changes and events that occur at the same recorded time.
  • Identify why an event at time zero cannot be represented by a positive-length interval.
  • Check reshaped data for gaps, overlaps, post-event rows, and altered event times.
  • Compare exact start-stop records with one-row-per-person and fixed-bin formats.

Why Reshape Longitudinal Records?

A survival record often begins with one row per person containing an event or censoring time, event status, and a sequence of treatment and covariate measurements. To represent changing histories over follow-up, the record can be expanded into intervals: each row describes one person over a span of time, with the treatment and other information applicable to that span. The challenge is to expand the record without moving an event, duplicating time at a boundary, or assigning a treatment measured after an event to the event interval.

The resulting data are often called start-stop or person-period data. Here, “period” need not mean a fixed-width calendar period: intervals can have different lengths, with boundaries chosen to reflect treatment updates, measurements, or the end of follow-up. The construction is a data representation, not a model-fitting step.

Definition: For person \(i\), let \(T_i\) be the event time and \(C_i\) the censoring time. The observed follow-up endpoint and event indicator are \(U_i=\min(T_i,C_i)\) and \(\Delta_i=I(T_i\leq C_i)\), using the convention that an event observed at the censoring time is counted as an event. A start-stop row has a start \(s_{ij}\), a stop \(e_{ij}\), and an event indicator \(Y_{ij}\). We use intervals \((s_{ij},e_{ij}]\), so an event at a shared boundary belongs to the interval ending at that boundary.

The event-at-censoring-time convention is appropriate only when the recorded data establish that the event was observed at that time. If a data system cannot distinguish an event from censoring at a tied timestamp, the tie must be resolved using the study’s ascertainment rules rather than silently assigned. Likewise, treatment and covariate values need a timing convention: a value measured at a boundary should not be treated as available before it was recorded.

Constructing the Intervals

For a person with \(U_i>0\), make a strictly increasing sequence of cut points \(0=b_{i0}<b_{i1}<\cdots<b_{im_i}=U_i\). Include every time at which the history relevant to the rows changes during follow-up, and include the endpoint \(U_i\). The person then contributes \(m_i\) rows, with \(s_{ij}=b_{i,j-1}\) and \(e_{ij}=b_{ij}\). Do not include cut points after \(U_i\): follow-up ends at the event or censoring time.

A practical timing convention is that a treatment change recorded at \(b_{ij}\) becomes effective immediately after \(b_{ij}\). The row ending at \(b_{ij}\) therefore reflects the treatment in force before the change; the next row, if there is one, reflects the updated treatment. An event at \(b_{ij}\) is assigned to the row ending there, not to a row beginning there. This convention matches the \((s,e]\) interval definition. If a study instead defines a treatment change as effective before events at the same timestamp, the data need a finer ordering or a different explicit convention.

Construction rule: For \(U_i>0\), set \(Y_{ij}=1\) on the final row if \(\Delta_i=1\), and set \(Y_{ij}=0\) on all other rows. If \(\Delta_i=0\), set every \(Y_{ij}=0\). Treatment and covariate fields on each row must describe the history applicable over that interval under the stated measurement-time convention.

Worked Example: An Event After Two Treatment Updates

A person enters follow-up at time 0, has treatment \(A=0\) until time 2, changes to \(A=1\) at time 2, and has a second recorded update at time 4 with treatment remaining \(A=1\). The event occurs at time 5, before censoring. Use updates as cut points, and let each change take effect just after its recorded time.

The observed endpoint is \(U=5\), and \(\Delta=1\). The cut points are \(0,2,4,5\), giving three intervals: \((0,2]\), \((2,4]\), and \((4,5]\). The first interval has \(A=0\); the latter two have \(A=1\). Since the event occurs at the endpoint of the third interval, the event indicators are \(0,0,1\).

StartStopTreatment over intervalEvent indicator
0200
2410
4511

The total observed duration is \(2+2+1=5\), the original event time. The final event row uses treatment \(A=1\), which was in force over \((4,5]\); no row is created after time 5.

What the Representation Preserves

The key properties can be checked directly from the construction. They depend on positive-length follow-up: if \(U_i>0\), the strict sequence of cut points makes every row have positive length. When \(\Delta_i=1\), the observed event must also occur at a positive time under this construction.

Result: For a person with \(U_i>0\), the intervals \((b_{i,j-1},b_{ij}]\) partition the observed follow-up \((0,U_i]\) without gaps or overlap of positive duration. Their lengths sum to \(U_i\). If \(\Delta_i=1\), exactly one row has \(Y_{ij}=1\), and its stop time is \(T_i=U_i\). If \(\Delta_i=0\), every row has \(Y_{ij}=0\).

Proof. The cut points are strictly increasing, so \(b_{ij}-b_{i,j-1}>0\) for every row. The adjacent intervals meet at their common boundary, with that boundary included in the interval ending there and excluded from the one starting there. Thus no boundary is counted twice, and their union is \((0,U_i]\). Their lengths telescope:

$$ \sum_{j=1}^{m_i}(b_{ij}-b_{i,j-1}) =b_{im_i}-b_{i0} =U_i. $$

If \(\Delta_i=1\), the construction assigns \(Y_{ij}=1\) only to the final row, and \(b_{im_i}=U_i=T_i\); hence there is exactly one event row and its stop is the event time. If \(\Delta_i=0\), the rule assigns zero to every row. \(\square\)

This result also gives a simple reconstruction check. For an event record, the stop of the unique row with \(Y_{ij}=1\) must equal the original event time. For a censored record, there must be no event row, and the final stop must equal the original censoring time.

Worked Example: Censoring Between Scheduled Updates

A person is event-free at time 0. Treatment is \(A=0\) through time 3 and becomes \(A=1\) immediately after time 3. The person is censored at time 4.5, before the next planned measurement at time 6.

Here \(U=4.5\) and \(\Delta=0\). Use cut points \(0,3,4.5\), not \(0,3,6\), because observation ends at censoring. The rows are \((0,3]\) with \(A=0\) and \((3,4.5]\) with \(A=1\); both have event indicator zero. Their lengths sum to \(3+1.5=4.5=U\). A row extending to time 6 would incorrectly represent the person as observed after censoring.

Boundary Cases and Data Checks

An event at a treatment-update time requires careful use of the endpoint rule. Suppose an update is recorded at time 4 and the event is also recorded at time 4. The event belongs to the interval ending at 4. Under the convention that the update takes effect just after time 4, the row ending at 4 contains the pre-update treatment. There is no post-update interval for this person because follow-up ends at the event. If the data indicate that treatment changed before the event at that timestamp, the timestamps alone do not encode that ordering; use recorded sequence information or state a scientifically justified tie rule.

Worked Example: Event at a History-Update Boundary

A person has treatment \(A=0\) on \((0,2]\), and a change to \(A=1\) is recorded at time 2. The event occurs exactly at time 2. With changes effective immediately after their timestamps, \(U=2\), \(\Delta=1\), and the sole interval is \((0,2]\). Its treatment is \(A=0\) and its event indicator is 1. The record does not contain an interval with \(A=1\): that treatment starts after follow-up has ended. Assigning \(A=1\) to the event row would contradict the chosen timing convention.

An event at time zero is a genuine boundary exception, not an ordinary positive-length interval. If \(T_i=0<C_i\), then \(U_i=0\) and \(\Delta_i=1\). No interval can satisfy both \(s_{ij}<e_{ij}\) and \(e_{ij}\leq U_i=0\). Therefore the positive-length construction and the result above require \(U_i>0\). Keep a time-zero event as a separate zero-time record or represent it with a study-specific baseline-event convention; do not invent a positive-length interval or claim that it has a usual event-indicator row. A censored record with \(U_i=0\) likewise contributes no positive-duration interval and should be retained separately if it is meaningful for the analysis.

After reshaping, verify these properties person by person:

  • Every interval has \(s_{ij}<e_{ij}\), and successive rows meet at their shared boundary.
  • The first start is 0, the final stop is \(U_i\), and no row extends beyond \(U_i\).
  • The row lengths sum to \(U_i\).
  • An observed event with \(U_i>0\) has exactly one event row, at the original event time; a censored record has none.
  • Treatment and covariate values agree with the measurement-time and boundary conventions, including at tied timestamps.

Gaps indicate omitted follow-up; overlaps can double-count time. Multiple event rows usually indicate that the event indicator was copied to every row rather than attached only to the terminal event interval. A row after an event or censoring time changes the observed follow-up record and must be corrected.

Choosing a Data Representation

One row per person is compact and can preserve the original event time and status, but it cannot directly display a changing treatment history as interval-specific values. Start-stop records make those changes explicit and preserve the exact endpoint when cut points are correctly chosen. Fixed-width bins are another possibility, but can shift event times to bin boundaries or obscure when treatment changed unless the binning rule is carefully specified. Exact start-stop intervals are preferable when the analysis needs the observed ordering and timing of history changes. They do not, by themselves, solve causal identification, determine appropriate weights, or choose a survival model.

The format is only as reliable as the source data and conventions. Coarsely recorded timestamps may not establish whether a treatment update preceded an event. Measurement error, missing history, and ambiguity about treatment effectiveness cannot be repaired by reshaping. Moreover, an interval row is not a new independent person: several rows from one person remain linked observations. The purpose here is faithful representation, not to justify treating rows as independent.

Key takeaway: Split follow-up at meaningful history changes and at the event or censoring endpoint. Under the \((s,e]\) convention, put an event indicator only on the interval ending at the observed event, and treat time-zero events separately because they cannot occupy a positive-length interval.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A person has event time 6, with treatment updates at times 2 and 5. What intervals and event indicators result?
  2. A person is censored at time 3.5, with an update at time 2 and a planned visit at time 4. Which cut points should be used, and why?
  3. An event and a treatment update are both recorded at time 4. Under the convention that treatment changes take effect just after their timestamps, which treatment is assigned to the interval ending at 4?
  4. Why can an event at time zero not be represented as an event row under the positive-length interval convention?
  5. A reshaped event record has event indicators \(0,1,1\). Name the error and give the required check.

Solutions. (1) The intervals are \((0,2]\), \((2,5]\), and \((5,6]\); their event indicators are \(0,0,1\), because the event is at the final stop, time 6. (2) Use cut points \(0,2,3.5\), producing \((0,2]\) and \((2,3.5]\). Do not include time 4 because follow-up ended at 3.5. Both indicators are zero. (3) Use the treatment in force before time 4 on the interval ending at 4; the change applies just after 4. (4) A positive-length row requires \(s<e\), but no such interval can end at or before \(U=0\). Keep the event as a separate zero-time record or apply a stated baseline convention. (5) The event has been assigned to more than one row. Check that exactly one indicator is 1 and that the stop of that row equals the original event time. \(\square\)

Clinical Biostats