Why Represent Treatment as a History?
In a longitudinal study, a person may receive different treatments at successive decision times. A description such as “treated” or “untreated” can therefore be incomplete: it may not say when treatment began, whether it stopped, or how its level changed. Representing treatment as a sequence keeps those distinctions visible.
The goal here is descriptive and not, by itself, causal. A treatment-history notation records what treatment values occurred at specified decision times. It does not establish that two people with the same recorded history are otherwise comparable, or that a particular treatment sequence caused an outcome.
This notation uses the same number of decision times for each person in the examples below. Before forming a sequence, specify what counts as a decision time and use the same indexing convention throughout the data set. The notation alone does not specify the length of time between decisions. For example, \(t=2\) means the second indexed decision, not necessarily two days after baseline.
A history through \(t\) is a prefix of the complete history: it contains the first \(t\) treatment values and no later ones. For convenience, the history before the first decision is empty, written \(\bar A_{i0}=\varnothing\). These prefixes make it possible to describe how a recorded sequence builds over successive decisions without replacing the sequence by one overall label.
Binary Treatment Histories
For a binary treatment, use a consistent coding such as \(A_{it}=0\) for “not receiving the specified treatment at decision \(t\)” and \(A_{it}=1\) for “receiving it.” This coding describes treatment at each decision separately. A history such as \((0,1,1,0)\) records no treatment at the first decision, treatment at the second and third, and no treatment at the fourth.
Worked Example: Recording Initiation and Discontinuation
In a hypothetical four-decision study, a treatment indicator is recorded for each person, with 1 meaning the person receives the treatment at that decision and 0 meaning the person does not. One participant has values \(0,1,1,0\).
The complete history is \(\bar A_{i4}=(0,1,1,0)\). Its prefixes are \(\bar A_{i1}=(0)\), \(\bar A_{i2}=(0,1)\), and \(\bar A_{i3}=(0,1,1)\). In words, the participant is not receiving treatment at the first decision, receives it at the next two, and is not receiving it at the last decision.
The number of decisions with treatment is \(0+1+1+0=2\). That count is a useful summary, but it is not the history: for example, \((1,0,1,0)\) also has two treated decisions and records a different path. Retaining the vector preserves when the recorded treatment values occurred.
For compact storage, a binary history can also be assigned an integer code. One convention is to treat the first decision as the most significant binary digit:
This code is convenient when \(K\) is fixed and the coding convention is stated. It is not a replacement for specifying the underlying treatment values and their order.
Worked Example: Encoding a Binary Sequence
Suppose a hypothetical participant’s history over four decisions is \((0,1,1,0)\). With the convention above, the weights for decisions 1 through 4 are \(2^3,2^2,2^1,2^0\), or 8, 4, 2, and 1.
Thus the history is stored as code 6 under this convention. To recover the sequence, express 6 in four binary digits: \(6=0110_2\), giving \((0,1,1,0)\). A different convention for digit order would give a different code, so the convention must travel with the stored value.
The encoding preserves the sequence because ordinary binary positional notation has a unique representation when the number of digits and their order are specified. More generally, for \(K\) binary decisions there are \(2^K\) possible histories, and the codes range from 0 to \(2^K-1\). The code is a label for the sequence, not a measurement on which arithmetic differences have a treatment interpretation. For example, code 6 is not “twice as much treatment” as code 3.
Multivalued Treatment Histories
Treatment at a decision may have more than two possible values. For example, a person might receive no treatment, a standard level, or an intensive level. Define the categories explicitly and use the same labels at every decision. If the categories are coded as \(0,1,2\), those digits identify categories; they do not automatically assert that the numerical distance from 0 to 1 equals the distance from 1 to 2.
When each decision has \(m\) possible categories coded \(0,\ldots,m-1\), a sequence can be stored as an ordered vector or as a base-\(m\) integer. With the first decision as the most significant digit, the code is \(\sum_{t=1}^{K} A_{it}m^{K-t}\). As with binary coding, the category map, number of decisions, and digit order must be known to decode the integer.
Worked Example: Encoding Three Treatment Levels
In a hypothetical three-decision study, let 0 mean no treatment, 1 mean standard treatment, and 2 mean intensive treatment. One participant’s history is \((2,0,1)\): intensive treatment at the first decision, none at the second, and standard treatment at the third.
There are three categories at each decision, so use base 3. The place-value weights are \(3^2=9\), \(3^1=3\), and \(3^0=1\).
The base-3 representation of 19 is \(201_3\), so code 19 decodes to \((2,0,1)\). This calculation depends on the stated category map and on reading the first decision as the most significant digit. The code does not make the categories quantitative; it only stores their ordered sequence.
A vector is often easier to inspect than a compact integer, particularly when treatment categories have meaningful names. In a report or data dictionary, state what each category means and whether the same categories apply at every decision. If an extra category is possible, such as “temporarily unavailable,” it should not be silently merged with “no treatment”; the definition of the recorded treatment values should make that distinction clear.
Continuous Treatments and Summaries
A treatment may instead be measured on a continuous scale, such as dose in milligrams per day. In that case, record the treatment history as a vector of measured values, with units attached. A base-\(m\) digit code is not an appropriate exact representation for unrestricted continuous values: there is no fixed finite set of digits that captures every possible value without rounding or loss.
Worked Example: Recording a Changing Dose
Consider a hypothetical participant with four weekly decisions. At each decision, the recorded value is the prescribed daily dose for the following week, in milligrams per day. The values are 0, 5, 5, and 10 mg/day.
The exact recorded history is \(\bar A_{i4}=(0,5,5,10)\) mg/day. Its arithmetic mean across the four decisions is
Because each value applies for one week, the total amount prescribed over those weeks is \(7(0+5+5+10)=140\) mg. This calculation uses the stated one-week duration and assumes the dose represented by each value applies throughout its week. The vector and the total answer different questions: the vector shows the dose at each decision, while the total does not show how the dose changed.
For continuous treatment, summaries such as a mean, maximum, cumulative amount, or number of increases can be useful when they match the descriptive question. But a summary generally discards some sequence information. For example, two hypothetical four-week dose histories, \((0,10,0,10)\) and \((5,5,5,5)\) mg/day, both have a sum of 20 mg/day-values and a mean of 5 mg/day. They do not represent the same sequence: one alternates between zero and 10 mg/day, while the other stays at 5 mg/day.
Units and intervals matter when calculating cumulative amounts. Adding dose values measured in mg/day gives a sum of daily-dose values, not by itself an amount in mg. To obtain an amount, the duration represented by each value must be specified and used in the calculation. If intervals differ in length, the values must be combined with those durations rather than treated as equally long intervals.
Storing and Presenting Histories
A history can be stored in a wide table, with one treatment column for each decision, or in a long table, with one row per person and decision. Either layout can represent the same sequence if the person identifier and decision index are retained.
| Layout | What a row represents | Example treatment fields |
|---|---|---|
| Wide | One person | \(A_{i1}, A_{i2}, \ldots, A_{iK}\) |
| Long | One person at one decision | Person identifier, decision index \(t\), and \(A_{it}\) |
In a long table, sorting rows by person and then by decision index makes the sequence explicit. In a wide table, the column labels must make the time order unambiguous. In either layout, keep the coding definition and units with the data. Otherwise a stored 1 could be unclear: it might indicate a treatment category, a binary indicator, or a quantity in some unit.
State the number of decisions and what each index refers to; use the same order for every person.
Specify the categories for a binary or multivalued treatment, or the measurement scale and units for a continuous treatment.
Retain one value for each decision in order, even if a summary or compact code is also stored.
Verify that another reader can identify the decision order, interpret every value, and recover the sequence if a code is used.
Common Mistakes and Why Representation Matters
The most common mistake is replacing the sequence with a single treatment label or total and then treating that summary as though it uniquely described the path. A count of treated decisions cannot distinguish early treatment from late treatment; a cumulative dose cannot in general distinguish steady dosing from intermittent dosing. If the timing or pattern is relevant to the question, retain the full history.
- Ignoring order. The sequences \((1,0,1)\) and \((1,1,0)\) contain the same values but are different histories because those values occur at different decision indices.
- Leaving codes undefined. An integer code is not interpretable without the number of decisions, digit order, and category mapping.
- Reading category codes as quantities. Coding categories as 0, 1, and 2 does not, by itself, justify interpreting differences between codes as meaningful treatment differences.
- Adding continuous values without units or durations. A dose expressed per day must be combined with the time for which it applies before interpreting a total amount.
A well-defined history is the basic record of treatment over repeated decisions. It makes the sequence available for later descriptions and analyses, while keeping the distinction between recorded treatment and any causal interpretation clear.
Check Your Understanding
Try these questions without looking back.
- For a binary treatment recorded at five decisions, how many possible complete histories are there?
- Using the binary coding convention in this tutorial, calculate the integer code for the history \((1,0,1,1)\).
- Three categories are coded 0, 1, and 2. What additional information is needed to interpret a base-3 code for a treatment history?
- Two four-decision dose histories have the same mean dose. Does that establish that their treatment histories are identical? Explain.
- A dose is recorded in mg/day at each weekly decision. What information is needed to calculate the total amount prescribed over the study period?