Data Management

Code time-varying exposure without using future information

Separate exposure history from a final label

When treatment starts or changes during follow-up, a single ever-exposed label can assign earlier time to an exposure that had not yet occurred. Begin with a dated history of exposure changes and an explicit rule for when each change becomes effective.

The survival package time-dependent-covariate vignette describes interval data and the requirement that current covariate values use information available at the time. Preserve the original dates and construct analysis intervals reproducibly, rather than manually editing exposure labels in the final table.

Specify the boundary convention

Record the time origin, interval start and stop, event indicator and exposure value. Define what happens when exposure starts on the same recorded date as an event. Date-only records may not establish within-day ordering; resolve that uncertainty through a prespecified rule and sensitivity analysis instead of inventing timestamps.

Check for overlapping intervals, gaps, zero-length intervals and events recorded more than once. Confirm that total interval duration equals each person's eligible follow-up. Keep the person identifier so repeated rows are not interpreted as independent participants.

Hypothetical example

A fictional person is followed from day zero to day 100, starts treatment after day 40 and has an event at day 100. Under a stated convention that exposure changes immediately after day 40, the data contain an unexposed interval (0, 40] and an exposed interval (40, 100], with the event only on the latter.

The durations are 40 and 60 days, totalling 100. Coding the person exposed from day zero would assign 40 days of pre-treatment time to treatment. If the start and event occur on the same day, this simple example no longer resolves their ordering.

Distinguish data coding from causal identification

Correct interval coding is necessary but does not make an exposure coefficient causal. Time-varying confounders affected by earlier treatment may require methods beyond ordinary covariate adjustment. State the intended interpretation and seek a design consistent with it.

Test a small synthetic history with changes, censoring and tied dates before running the full derivation. Report the exposure rule, time scale, interval convention and treatment of missing histories. Use the time-zero alignment worksheet to preserve the design and the analysis test-oracle worksheet for boundary cases. A readable interval table should allow another analyst to reconstruct exactly what the model considered known at each event time.

Source verification: 6 November 2026. Examples are hypothetical.

Related reading

Reading path: Prepare data. Guide 44 of 50. Choose any guide to suit your project.

Data Management

Balance assay batches before processing samples

Keep biological comparisons from becoming inseparable from plates, runs or processing dates.

Data Management

Audit a case-cohort sample before modelling

Preserve subcohort membership, cohort sizes and sampling strata so the analysis reflects the design.

Browse this reading pathTools for this stageGuides and downloads for this stage