Why Treatment Coding Changes the Comparison
In a longitudinal study, treatment is recorded at several decision times, but a regression may include only one treatment variable. Which variable is used determines which participants the model treats as having the same exposure. A coefficient for the latest treatment does not, by itself, compare complete treatment strategies; nor does a coefficient for an earlier treatment necessarily describe its effect after later treatment is considered.
Let \(A_0,\ldots,A_{K-1}\) denote treatment at \(K\) ordered decision times, and let \(Y_K\) be an outcome measured afterward. For a particular outcome time, call \(A_{K-1}\) the current treatment (the most recent decision before the outcome), \(A_{K-2}\) the one-period lagged treatment, and \((A_0,\ldots,A_{K-1})\) the treatment history. These labels are relative to the outcome time: a treatment can be current for one outcome and lagged for a later one.
For example, with two treatment decisions, \(A_0\) and \(A_1\), and a later outcome \(Y_2\), a current-treatment model includes \(A_1\), a lagged-treatment model includes \(A_0\), and a history model distinguishes the four possible sequences \(00,10,01,11\). Covariates may also appear in any model. A regression coefficient is interpreted conditional on the variables included and under the model’s functional-form assumptions. It is not automatically a causal effect.
What Each Coding Can Distinguish
A regression using only \(A_1\) assigns the same treatment code to histories \(01\) and \(11\): both have \(A_1=1\). It also groups \(00\) with \(10\), since both have \(A_1=0\). A regression using only \(A_0\) instead groups histories according to their first decision. In either case, histories with different values of the omitted treatment can be combined.
A history-coded regression can keep those sequences separate. One option is a categorical variable with one category per observed sequence. Another, when treatment is binary, is a regression with \(A_0\), \(A_1\), and possibly their interaction. Without the interaction, that model restricts the history-specific means to an additive pattern; it does not generally reproduce four unrestricted means.
These distinctions concern the outcome comparisons the regression can represent. If a covariate is included, the comparisons are conditional on that covariate under the specified model. If it is omitted, the groups may differ in its distribution. Neither coding alone establishes that the comparison is causal.
Worked Example: Current and Lagged Treatment Give Different Group Comparisons
Suppose each of the four two-decision histories occurs equally often, and the mean outcome within each history is as follows. For simplicity, take these as the observed means in the data.
| History \((A_0,A_1)\) | Mean outcome |
|---|---|
| 00 | 2 |
| 10 | 5 |
| 01 | 4 |
| 11 | 9 |
Current-treatment coding. The group with \(A_1=0\) contains histories \(00\) and \(10\), so its mean is \((2+5)/2=3.5\). The group with \(A_1=1\) contains \(01\) and \(11\), so its mean is \((4+9)/2=6.5\). The unadjusted current-treatment contrast is \(6.5-3.5=3\).
Lagged-treatment coding. The group with \(A_0=0\) contains \(00\) and \(01\), with mean \((2+4)/2=3\). The group with \(A_0=1\) contains \(10\) and \(11\), with mean \((5+9)/2=7\). The lagged-treatment contrast is \(7-3=4\).
The calculations differ because the two regressions group the histories differently. The equal history frequencies make these marginal group means especially transparent; with unequal frequencies, each group mean would use its own history frequencies. Neither difference is, just by being calculated, a contrast between interventions.
History Models and Their Contrasts
A saturated history model assigns a separate conditional mean to each treatment sequence, within any specified covariate stratum. For two binary decisions and no additional covariates, one way to write it is to use indicators for the four histories. Equivalently, use the following interaction model, which has one parameter for each history-specific mean:
The fitted means for \(00,10,01,11\) are respectively \(\beta_0\), \(\beta_0+\beta_1\), \(\beta_0+\beta_2\), and \(\beta_0+\beta_1+\beta_2+\beta_{12}\). Thus the interaction permits the difference between \(A_0=1\) and \(A_0=0\) to depend on \(A_1\), and vice versa.
To justify the result, suppose every history category has observations and the model contains a separate indicator for each category (with one category as the reference). Least squares fits the mean outcome within each category: for category \(h\), minimizing \(\sum_{i:H_i=h}(Y_i-\mu_h)^2\) gives \(\hat{\mu}_h=\bar{Y}_h\), since differentiating with respect to \(\mu_h\) yields \(-2\sum_{i:H_i=h}(Y_i-\mu_h)=0\). Therefore the fitted contrast for histories \(h\) and \(h'\) is \(\hat{\mu}_h-\hat{\mu}_{h'}=\bar{Y}_h-\bar{Y}_{h'}\). The same interpretation applies to a correctly specified conditional-mean model with covariates, at a fixed covariate value, provided the model allows the relevant history means to differ freely. \(\square\)
Worked Example: Computing Contrasts From a History Model
Use the history means \(2,5,4,9\) for \(00,10,01,11\). In the interaction model, the mean for \(00\) gives \(\beta_0=2\). The mean for \(10\) gives \(2+\beta_1=5\), so \(\beta_1=3\). The mean for \(01\) gives \(2+\beta_2=4\), so \(\beta_2=2\). Finally, the mean for \(11\) gives \(2+3+2+\beta_{12}=9\), so \(\beta_{12}=2\).
The contrast \(10\) versus \(00\) is \(5-2=3\), matching \(\beta_1\). The contrast \(01\) versus \(00\) is \(4-2=2\), matching \(\beta_2\). The contrast \(11\) versus \(00\) is \(9-2=7=\beta_1+\beta_2+\beta_{12}\). Omitting the interaction would force the predicted mean for \(11\) to be \(2+3+2=7\), not the observed history mean \(9\). Thus a model with only current and lagged main effects cannot represent all four means in this example.
Why a Current-Treatment Model Restricts History Comparisons
A regression using only the current treatment makes a specific equality restriction: at the same values of any other included predictors, histories with the same current treatment receive the same fitted mean. For two treatment decisions, a model using \(A_1\) alone cannot assign separate fitted means to \(01\) and \(11\). This is a feature of the coding, not a computational error.
For an unadjusted linear regression with an intercept and binary \(A_1\), the fitted mean for each \(A_1\) group equals that group’s sample mean. This follows from the least-squares objective: the intercept and treatment coefficient allow one fitted value for \(A_1=0\) and another for \(A_1=1\), and each fitted value minimizes the sum of squared deviations in its group at that group’s mean. The result does not say that the two groups have the same distribution of earlier treatment or covariates; it says only that the model does not distinguish those differences in its treatment coding. \(\square\)
Worked Example: Different Histories Share the Same Current Code
In the history-mean table, histories \(01\) and \(11\) both have current treatment \(A_1=1\), but their means are 4 and 9. A regression using \(A_1\) alone cannot fit both means separately. With equal numbers in the two histories, it assigns the \(A_1=1\) group mean \((4+9)/2=6.5\) to each history. The fitted value is 2.5 above the mean in history \(01\) and 2.5 below the mean in history \(11\).
This example also explains why a current-treatment coefficient can change when the mixture of earlier histories changes. If history \(11\) becomes more common among those with \(A_1=1\), their group mean can rise even if none of the history-specific outcome means changes. The coefficient then reflects both the chosen coding and the group composition.
Assumptions, Diagnostics, and Alternatives
The arithmetic interpretations above require the stated regression to be identifiable: the relevant treatment groups must be observed, and the design matrix must have full column rank for the coefficients being estimated. A saturated history model needs data in each history it is meant to compare. With covariates, the model must also have adequate covariate support across those histories for the conditional comparisons of interest. If an interaction is omitted, the resulting equality restrictions need substantive and empirical scrutiny.
Useful diagnostics include checking the number of observations in each history, inspecting history-specific outcome summaries, and comparing observed means with the fitted values from a restricted model. Large residual patterns by history can reveal that a current-only or additive model is combining groups with different outcomes. Sparse cells warn that estimates from a fully history-coded regression may be unstable or imprecise. A missing history is not repaired by assigning it a model-based estimate and then treating that estimate as an observed comparison.
| Coding | What is grouped together? | Main limitation |
|---|---|---|
| Current treatment only | Histories sharing the most recent treatment | Earlier histories are not separately represented |
| Lagged treatment only | Histories sharing the selected earlier treatment | Later treatments are not separately represented |
| Separate treatment indicators, no interactions | Histories described by an additive pattern | Rules out some history-specific differences |
| Saturated history categories | Only the same complete observed sequence | Requires sufficient data and support for each history |
A common mistake is to read a coefficient for the latest treatment as “the effect of following treatment rather than not following it.” That conclusion does not follow from the coding: the coefficient compares the model’s \(A_{K-1}=1\) and \(A_{K-1}=0\) groups, possibly conditional on included variables, while grouping together distinct earlier histories. A correction is to state the exact coding and comparison, then ask whether that comparison is the scientific contrast of interest and whether the model and design support it. Causal interpretation additionally requires appropriate causal assumptions; the regression coding alone supplies none.
No single coding is universally best. Current- or lagged-treatment models are more parsimonious when that restricted comparison is adequate for the question. A treatment-history model represents richer contrasts but uses more parameters and can be unstable when histories are rare. A main-effects model is a middle ground only when its additive restrictions are defensible. These are alternatives in how the outcome regression represents exposure; they are not interchangeable interpretations of one coefficient.
Check Your Understanding
Answer each question, then check the solutions below.
- For outcome \(Y_3\) after decisions \(A_0,A_1,A_2\), which variable is current, and which is one-period lagged?
- In a two-decision study, which histories are grouped together by a regression using \(A_1\) alone?
- In a saturated history model with means 3 for history \(00\) and 8 for history \(11\), what is the fitted contrast \(11\) versus \(00\)?
- Why can a current-treatment coefficient change when the proportions of earlier histories change?
- Name one condition needed to estimate all four means in a saturated model for two binary treatments.
Solutions. (1) \(A_2\) is current and \(A_1\) is one-period lagged relative to \(Y_3\). (2) It groups \(00\) with \(10\), and \(01\) with \(11\), because each pair shares \(A_1\). (3) The contrast is \(8-3=5\). (4) The current-treatment group mean combines the outcomes of its earlier-history groups; changing their proportions changes the combined mean even if the history-specific means stay fixed. (5) Each of the four histories must be observed; for a covariate-adjusted comparison, there must also be adequate relevant covariate support.