Tutorials › Pharmacometric Workflows and Reproducible Modeling › Derived Covariates from Demographics

Data Specification and Dataset Preparation · Tutorial 30 of 399

Derived Covariates from Demographics

You will learn to calculate and validate age covariates from demographic dates without hiding date conventions or uncertainty.

Intermediate 10 min read

What You'll Learn

  • Calculate completed-calendar-year age from birth and reference dates.
  • Apply and document a consistent convention for February 29 birthdays.
  • Handle partial dates without inventing a precise birth date.
  • Distinguish completed age from elapsed-time measures expressed in years.
  • Retain source dates and check derived ages at important boundaries.

Why Derived Demographic Covariates Need Explicit Rules

Age is often used as a covariate in pharmacometric analyses, but it is usually derived from two dates rather than recorded as a fixed quantity: a date of birth and a date at which age is evaluated. That reference date might be study entry or the date of an observation. A calculated age is therefore meaningful only when both dates and the calculation convention are clear.

A one-day difference can change completed age at a birthday. Leap-day births add another boundary: in a non-leap year, the data specification must say whether the birthday anniversary is treated as February 28 or March 1. Partial dates create a different problem: they may not support one exact age at all. These are not cosmetic details. A derived value can change eligibility, covariate assignment, or interpretation if the dates or convention are handled inconsistently.

Definition: A derived demographic covariate is a variable calculated from demographic source fields according to a specified rule. For completed-calendar-year age, the inputs are a documented date of birth and a documented reference date. The derived value is the number of birthdays reached by the reference date under the stated calendar convention.

Define the Age Measure Before Calculating It

Use a consistent date representation, such as year-month-day, and specify what each date means. The reference date should be chosen for the analysis question: age at study entry is not interchangeable with age at each sample or visit. If an input is stored as a timestamp rather than a calendar date, document how its date is determined before calculating age; time-zone conversion near midnight can otherwise change the calendar day.

For a complete birth date \(b\) and reference date \(r\), let \(Y_b\) and \(Y_r\) be their calendar years. Define \(A_c(b,Y_r)\) as the birthday anniversary in year \(Y_r\), using convention \(c\). For a birth date other than February 29, this anniversary has the same month and day as the birth date. For a February 29 birth in a non-leap year, choose and document one of these common rules:

  • February 28 convention: the anniversary is February 28.
  • March 1 convention: the anniversary is March 1.

In a leap year, the anniversary of a February 29 birth is February 29 under either rule. The convention should be applied consistently wherever the derived age is used.

$$ \operatorname{Age}_{\mathrm{completed}}(b,r;c) = (Y_r-Y_b) - I\!\left[r < A_c(b,Y_r)\right], \qquad r \geq b $$

Here \(I[\cdot]\) equals 1 when the condition inside the brackets is true and 0 otherwise. The result is an integer number of completed years. The condition \(r \geq b\) is required: a reference date before birth indicates an invalid date pair for an age calculation, not a meaningful negative age.

Key distinction: Completed-calendar-year age counts birthdays reached. An elapsed-time measure in years instead divides elapsed time by a specified year length. Those measures can differ, so a dataset specification should name the intended measure and its units rather than treating them as interchangeable.

Why the Completed-Age Formula Works

The calendar-year difference \(Y_r-Y_b\) counts how many year boundaries separate the two dates. If the birthday anniversary in the reference year has not yet arrived, that count includes one birthday that the person has not reached; subtracting 1 corrects it. If the reference date is on or after the anniversary, all those birthdays have occurred, and no subtraction is needed.

For example, when the birth date is November 20, 1987, and the reference date is November 19, 2024, the calendar-year difference is \(2024-1987=37\). The anniversary is November 20, 2024, which is later than the reference date, so the indicator is 1 and the completed age is \(37-1=36\). On November 20, the anniversary has arrived, the indicator is 0, and the completed age is 37.

The anniversary function matters for February 29 births. The formula does not, by itself, settle what the anniversary should be in a non-leap year. The selected convention determines \(A_c\), and the comparison with the reference date then follows the same rule as for any other birthday.

Worked Example: A February 29 Birth Under Two Conventions

Suppose a participant was born on February 29, 2004. Calculate completed age on February 28 and March 1, 2023, under both documented anniversary conventions. The dates are hypothetical.

On February 28, 2023, using the February 28 convention. The anniversary is February 28, 2023. The reference date is on the anniversary, so the indicator is 0:

$$ (2023-2004)-0=19\text{ years}. $$

On February 28, 2023, using the March 1 convention. The anniversary is March 1, 2023. February 28 is before that anniversary, so the indicator is 1:

$$ (2023-2004)-1=18\text{ years}. $$

On March 1, 2023, under either convention. The reference date is on or after either convention's anniversary. The indicator is 0, giving \(2023-2004=19\) completed years. The difference between the conventions is therefore visible on February 28 in this non-leap year, but not on March 1.

Worked Example: Checking the Day Before, On, and After a Birthday

A hypothetical participant was born on November 20, 1987. Find completed age on November 19, November 20, and November 21, 2024. No leap-day convention is needed because this birth date has an ordinary calendar anniversary.

The calendar-year difference for each reference date is \(2024-1987=37\), and the anniversary is November 20, 2024.

  • November 19: before the anniversary, so age is \(37-1=36\) years.
  • November 20: on the anniversary, so age is \(37-0=37\) years.
  • November 21: after the anniversary, so age is \(37-0=37\) years.

This three-date check is a useful boundary test: age should increase by one on the birthday under the selected convention, not the day before or the day after.

Partial Dates and Uncertainty

A partial date does not identify one exact date of birth. Do not fill in an unknown day or month with a convenient value and then present the resulting age as exact. If the available demographic information gives a set of possible birth dates, calculate the possible ages over that set. If those dates imply different ages at the reference date, report an age range or mark exact completed age as unavailable according to the analysis specification.

The range must follow the recorded precision and documented assumptions. For example, a known month and year with an unknown day generally leaves multiple possible birthdays. A known year alone leaves still more. If the source provides an explicit convention for partial dates, apply it as specified and retain the indication that the date was partial; a derived age should not make the original uncertainty disappear.

Worked Example: Age From a Birth Date With an Unknown Day

Suppose a hypothetical source records the date of birth as July 2000, with no day available. The reference date is July 15, 2024. For this example, assume the birth date could be any day from July 1 through July 31, 2000, and use ordinary calendar anniversaries.

If the birth day was July 1 through July 15, the 2024 anniversary has occurred by the reference date. The completed age is \(2024-2000=24\) years. If the birth day was July 16 through July 31, the anniversary has not yet occurred, so the completed age is \(24-1=23\) years.

The available information therefore supports completed ages from 23 to 24 years, but not one exact completed age. Replacing the unknown day with July 1 would produce 24; replacing it with July 31 would produce 23. Either choice would create unsupported precision. Preserve the partial-date status and follow the analysis specification for representing the resulting uncertainty.

Keep the Source Fields and Make the Rule Reproducible

A derived age should supplement, not replace, its source dates. Retain the recorded birth-date fields—including their original precision—and the reference date used for each calculation. Keep the derived value distinguishable from those source fields. Record the age definition, leap-day convention, and any policy for partial or invalid dates in the data specification or associated documentation. That allows another analyst to understand what was calculated and to recalculate it if the convention changes.

Before calculating, establish how missing or incomplete inputs are handled. A missing date should not silently become a default date, and an incomplete date should not be treated as complete. A reference date earlier than birth should be flagged for review rather than converted into an age. These rules help distinguish a legitimate derived value from one created by an accidental parsing or data-entry error.

Validation and Common Failure Modes

Test the calculation at boundaries, not only on ordinary dates. A value can look plausible for most records while failing exactly on a birthday, around February 29, or when a date is incomplete. Useful checks include the following:

  • Compare the day before, the anniversary itself, and the day after an ordinary birthday.
  • For February 29 births, test both the documented convention and a non-leap reference year.
  • Confirm that a reference date before birth is flagged and that missing or partial inputs do not produce an unsupported exact age.
  • Check that age is a nonnegative integer when the requested measure is completed-calendar-year age and the dates are valid.
  • Confirm that each derived value uses the intended reference date, such as study entry rather than an unrelated later visit.

A frequent mistake is to subtract birth year from reference year and stop. For the November example above, that would return 37 on November 19, even though the participant had not yet reached the 2024 birthday. The correction is to compare the reference date with the anniversary in the reference year and subtract one when that anniversary is still in the future.

Another mistake is to use a single birthday comparison formula while claiming that either February 28 or March 1 is acceptable for non-leap years. The formula must use the selected convention to construct the anniversary before making the comparison. Alternatively, a project may standardize on one convention; it must still state that choice rather than leaving it implicit.

Choosing Between Age Definitions

Completed age is useful when the analysis or data specification calls for age in whole years. Some applications instead require an age measure with finer resolution. One possible definition is elapsed days divided by a specified number of days per year, but that definition must state how elapsed days and the year-length denominator are determined. It is not the same calculation as completed age and may yield a different numerical value.

ApproachWhat it representsKey requirement
Completed-calendar-year ageNumber of birthdays reached by the reference dateDefine the reference date and the February 29 convention
Elapsed time expressed in yearsElapsed duration divided by a specified year lengthDefine the date or time calculation and the year-length rule
Age from a partial birth dateA set or range of possible ages when the exact date is unknownRepresent the date uncertainty rather than inventing a day

The choice depends on the intended covariate definition, not on which calculation is easiest to produce. If a model specification requires a particular age measure, use that definition consistently and make its units clear. The limitations remain important: age derived from dates cannot be more precise than those dates, and no formula can resolve an ambiguous or incorrectly recorded source date by itself.

Key takeaway: A defensible age covariate requires a defined measure, a reference date, a documented birthday convention, and honest treatment of partial dates. Preserve the demographic source fields so the calculation remains interpretable and reproducible.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. A participant was born on May 10, 1995. What is completed age on May 9 and May 10, 2024?
  2. For a February 29, 2000 birth, what is completed age on February 28, 2023, using the March 1 convention?
  3. A date of birth is recorded only as October 1980. The reference date is October 5, 2024. Why may one exact completed age be unsupported?
  4. Why should the source birth date be retained after a derived age field has been calculated?

Solutions. (1) The calendar-year difference is \(2024-1995=29\). On May 9 the anniversary has not arrived, so age is \(29-1=28\) years; on May 10 it is \(29\) years. (2) Under the March 1 convention the 2023 anniversary is March 1. February 28 is before it, so age is \((2023-2000)-1=22\) years. (3) The unknown day could be October 1 through October 5, in which case the birthday has occurred and age is 44, or October 6 through October 31, in which case age is 43. Without further information, the exact completed age is not identified. (4) Retaining the source date and its precision makes the derived value auditable and allows it to be recalculated if the reference date, definition, or convention changes.

Clinical Biostats