Causal Inference for Data Science


In-depth Articles

1. Correlation vs Causality

Correlation measures the degree of linear association between two variables, but it does not imply causation. The distinction between correlation and causality is fundamental in empirical research. There are several types of relationships between variables:

Types of Relationships

  • Direct causality: \(X \rightarrow Y\). A change in \(X\) directly causes a change in \(Y\). Example: smoking causes lung cancer.
  • Inverse causality: \(Y \rightarrow X\). What we think is the cause is actually the effect. Example: police presence and crime rates — more police are deployed where crime is high, not the reverse.
  • Cyclic (simultaneous) causality: \(X \leftrightarrow Y\). Both variables cause each other simultaneously. Example: supply and demand jointly determine price and quantity.
  • Chain causality: \(X \rightarrow Z \rightarrow Y\). The effect of \(X\) on \(Y\) is mediated through an intermediate variable \(Z\). Example: education → income → health outcomes.
  • Confounded relationship: \(X \leftarrow Z \rightarrow Y\). A common cause \(Z\) drives both \(X\) and \(Y\), creating a spurious correlation. Example: ice cream sales and drowning are both driven by temperature.
  • Tautological relationship: \(X\) and \(Y\) measure essentially the same construct. Example: correlating GDP with national income — they are definitionally linked.
  • Multivariate causality: Multiple variables jointly cause the outcome: \((X_1, X_2, \ldots, X_k) \rightarrow Y\). The effect of each variable depends on the others.
  • Spurious correlation: A statistical association that arises purely by chance or through data mining, with no meaningful causal mechanism. Example: per capita cheese consumption correlating with deaths by bedsheet tangling.

The key insight is that observational data can reveal correlations, but establishing causality requires either experimental design or careful econometric identification strategies.




2. Causal Model vs Predictive Model

There is a fundamental difference in how economists and data scientists approach modeling. These two paradigms have different goals, assumptions, and evaluation criteria.

The Economist's Approach (Causal/Explanatory)

  • Theory-driven: starts from economic theory and derives testable hypotheses
  • Retrospective: explains why something happened (ex-post analysis)
  • Goal: unbiased estimation of causal parameters
  • Model selection: guided by theory, not by in-sample fit
  • Key concern: internal validity — is the estimated effect truly causal?
  • Typical output: a single coefficient \(\hat{\beta}\) with a standard error and confidence interval

The Data Scientist's Approach (Predictive)

  • Data-driven: lets the data reveal patterns without imposing strong structural assumptions
  • Prospective: predicts what will happen in the future (ex-ante forecasting)
  • Goal: minimize out-of-sample prediction error (bias-variance tradeoff)
  • Model selection: guided by cross-validation, information criteria
  • Key concern: generalization — does the model perform well on unseen data?
  • Typical output: a predicted value \(\hat{Y}\) with prediction intervals

The Bias-Variance Tradeoff

The predictive approach explicitly manages the decomposition of expected prediction error:

\[ E[(Y - \hat{f}(X))^2] = \text{Bias}[\hat{f}(X)]^2 + \text{Var}[\hat{f}(X)] + \sigma^2_\varepsilon \]

A causal model prioritizes minimizing bias (unbiasedness of \(\hat{\beta}\)), even at the cost of higher variance. A predictive model accepts some bias if it substantially reduces variance, improving overall prediction accuracy.




3. Causal Effect Parameters

In the potential outcomes framework, each unit \(i\) has two potential outcomes: \(Y_{1i}\) (outcome if treated) and \(Y_{0i}\) (outcome if not treated). The individual treatment effect is \(\tau_i = Y_{1i} - Y_{0i}\), which is never fully observable (the fundamental problem of causal inference).

We define three key population-level causal parameters:

Average Treatment Effect (ATE)

The expected causal effect across the entire population:

\[ ATE = E[Y_1 - Y_0 | X] = E[Y_1 | X] - E[Y_0 | X] \]

This answers: "What is the average effect of the treatment if we randomly assigned everyone?"

Treatment Effect on the Treated (TTE / ATT)

The expected causal effect among those who actually received treatment:

\[ TTE = E[Y_1 - Y_0 | X, D=1] = E[Y_1 | X, D=1] - E[Y_0 | X, D=1] \]

This answers: "What was the effect of the treatment on those who were treated?" The counterfactual \(E[Y_0 | X, D=1]\) — what would have happened to treated units had they not been treated — is unobservable.

Treatment Effect on the Untreated (UTE / ATU)

The expected causal effect among those who did not receive treatment:

\[ UTE = E[Y_1 - Y_0 | X, D=0] = E[Y_1 | X, D=0] - E[Y_0 | X, D=0] \]

This answers: "What would the effect have been on those who were not treated, had they been treated?" Relevant for policy questions about expanding a program.

Note that \(ATE = Pr(D=1) \cdot TTE + Pr(D=0) \cdot UTE\). The three parameters coincide only under constant treatment effects or random assignment.




4. The Econometric Approach

The workhorse of empirical economics is Ordinary Least Squares (OLS) regression. Consider the linear model:

\[ Y_i = \beta_0 + \beta_1 D_i + X_i'\gamma + \varepsilon_i \]

where \(D_i\) is the treatment indicator and \(X_i\) is a vector of controls. OLS estimates \(\hat{\beta}_1\) as the causal effect of treatment. However, the OLS estimate is only valid if \(E[\varepsilon_i | D_i, X_i] = 0\) (exogeneity).

Five Threats to Internal Validity

Internal validity means the estimated effect is truly causal within the study's context. OLS can fail due to:

  1. Omitted Variable Bias (OVB): A variable correlated with both \(D\) and \(Y\) is excluded from the model. The bias is: \[ \text{Bias}(\hat{\beta}_1) = \frac{Cov(D, Z)}{Var(D)} \cdot \gamma_Z \] where \(Z\) is the omitted variable and \(\gamma_Z\) its true coefficient.
  2. Sample Selection Bias: The sample is not representative of the population of interest. Self-selection into treatment makes the treated and control groups non-comparable.
  3. Reverse Causality (Simultaneity): \(Y\) also affects \(D\), creating a feedback loop. OLS cannot disentangle the direction of causality.
  4. Wrong Functional Form: The true relationship is nonlinear, but we impose a linear specification. This leads to misspecification bias.
  5. Measurement Error: The treatment variable \(D\) or outcome \(Y\) is measured with error. Classical measurement error in \(D\) attenuates the estimated coefficient toward zero.

Internal vs External Validity

  • Internal validity: The causal effect is correctly identified within the study's sample and setting. Threats: all five above.
  • External validity: The causal effect generalizes to other populations, settings, and time periods. Threats: differences in population composition, institutional context, general equilibrium effects, Hawthorne effects.

A study can be internally valid but not externally valid (e.g., a perfectly designed RCT in a specific village may not generalize to national policy).




5. Big Data in Causal Inference

Big Data refers to datasets that are too large, too fast, or too complex to be processed by traditional database management tools. The "V's" of Big Data are: Volume, Velocity, Variety, and Veracity.

Characteristics Relevant to Causal Inference

  • Real-time data: continuous streams (clicks, transactions, sensor data) enable near-immediate causal analysis
  • Large scale: millions or billions of observations — increases statistical power but also amplifies small biases
  • New types of variables: text, images, network connections, geolocation — potential instruments or controls previously unavailable
  • Unstructured data: requires NLP, computer vision, or other ML preprocessing before causal analysis

Advantages

  • More granular heterogeneity analysis (treatment effects by subgroup)
  • Better control variables reduce omitted variable bias
  • Natural experiments become detectable at scale
  • A/B testing can be deployed continuously and cheaply
  • High-dimensional controls via ML methods (LASSO, Random Forests)

Limits

  • Big data ≠ good data: selection bias, measurement error, and confounding persist regardless of sample size
  • Spurious correlations multiply: with thousands of variables, many will correlate by chance
  • p-hacking at scale: large samples make nearly everything "statistically significant"
  • Identification is not a sample size problem: no amount of data resolves omitted variable bias or reverse causality without a credible identification strategy
  • Algorithmic confounding: platform algorithms (recommendations, targeting) create endogenous data-generating processes



6. Prediction Policy Problems

Kleinberg et al. (2015) identify a class of problems where prediction (not causal inference) is the binding constraint for policy. Examples: predicting which patients will benefit from surgery, which students will drop out, which loans will default. The policy action is known; the question is who to target.

Regularization Methods: LASSO and Ridge

In high-dimensional settings (\(p \gg n\) or many irrelevant features), OLS overfits. Regularization adds a penalty to the loss function:

\[ \hat{\beta} = \arg\min_\beta \left\{ \sum_{i=1}^n (Y_i - X_i'\beta)^2 + \lambda \cdot R(f) \right\} \]

where \(R(f) = \|\beta\|_\lambda\) is the regularization function:

  • \(\lambda = 0\): no penalty → standard OLS
  • \(\lambda\) with \(L_2\) norm (Ridge): \(R(f) = \sum_j \beta_j^2\). Shrinks coefficients toward zero but never sets them exactly to zero. Handles multicollinearity.
  • \(\lambda\) with \(L_1\) norm (LASSO): \(R(f) = \sum_j |\beta_j|\). Performs variable selection by setting some coefficients exactly to zero. Produces sparse models.

The general Elastic Net penalty nests both: \(R(f) = \alpha\|\beta\|_1 + (1-\alpha)\|\beta\|_2^2\).

Athey & Imbens (2015): Robustness Approach

Athey and Imbens (2015) propose using ML methods for causal inference while maintaining valid statistical inference. Key ideas:

  • Sample splitting (honest estimation): use one part of the data to build the model (discover structure) and another to estimate treatment effects (inference). This avoids overfitting-driven bias in causal estimates.
  • Cross-fitting: swap the roles of the two halves and average, for efficiency.
  • Causal forests: adapt random forests to estimate heterogeneous treatment effects \(\tau(x) = E[Y_1 - Y_0 | X=x]\) with valid confidence intervals.

The fundamental principle: ML is used as a tool within a causal identification framework, not as a replacement for it.




7. Causal Inference Methods Overview

TTTC Framework: Train, Test, Treat, Compare

A practical framework for deploying causal inference in business settings:

  1. Train: build a predictive model to identify heterogeneous treatment effects or select target populations
  2. Test: validate the model on held-out data to ensure generalization
  3. Treat: deploy the treatment (intervention, policy, marketing campaign) to the selected group
  4. Compare: evaluate the causal impact by comparing treated vs. control outcomes using appropriate methods

Heterogeneous Treatment Effects

The ATE masks important heterogeneity. Treatment effects may vary systematically by subgroup:

\[ \tau(x) = E[Y_1 - Y_0 | X = x] \]

This is the Conditional Average Treatment Effect (CATE). Methods to estimate it include: subgroup analysis, causal forests (Athey & Imbens), Bayesian Additive Regression Trees (BART), and meta-learners (S-learner, T-learner, X-learner).

Randomized vs Natural Experiments

  • Randomized Controlled Trials (RCTs): the gold standard. Random assignment ensures \(E[Y_0|D=1] = E[Y_0|D=0]\), eliminating selection bias. Limitations: ethical constraints, compliance issues, external validity concerns, cost.
  • Natural experiments: exploit exogenous variation created by nature, policy changes, or institutional rules (not by the researcher). Examples: lottery-based school assignment, regression discontinuity at policy thresholds, draft lotteries.

Threats to Experimental Validity

  • Non-compliance: not everyone assigned to treatment actually takes it (Intent-to-Treat vs. Local Average Treatment Effect)
  • Attrition: differential dropout between treatment and control groups
  • Spillovers (SUTVA violation): treatment of one unit affects outcomes of others
  • Hawthorne effect: subjects modify behavior because they know they're being observed
  • John Henry effect: control group members compensate by working harder



8. Rubin's Causal Model (Potential Outcomes Framework)

The Rubin Causal Model (RCM) formalizes causality through counterfactuals. For each unit \(i\):

The fundamental problem of causal inference: we only observe one potential outcome per unit, never both.

Observable Quantities

What we can observe from the data:

  • \(E[Y_0 | D=0]\): average outcome of untreated units (observable)
  • \(E[Y_1 | D=1]\): average outcome of treated units (observable)

The naive comparison yields:

\[ E[Y_1|D=1] - E[Y_0|D=0] = \underbrace{E[Y_1 - Y_0|D=1]}_{TTE} + \underbrace{E[Y_0|D=1] - E[Y_0|D=0]}_{\text{Selection Bias}} \]

Only if selection bias equals zero (random assignment) does the naive comparison identify the TTE.

When Selection is Observable (Selection on Observables)

If, conditional on observed covariates \(X\), treatment assignment is independent of potential outcomes:

\[ (Y_0, Y_1) \perp D \,|\, X \qquad \text{(Conditional Independence Assumption / Unconfoundedness)} \]

Techniques: OLS with controls, matching, propensity score methods, inverse probability weighting.

When Selection is Not Observable (Selection on Unobservables)

If unobserved factors jointly determine treatment and outcome, we need special identification strategies:

  • Instrumental Variables (IV): exploit exogenous variation in treatment via an instrument
  • Difference-in-Differences (DID): exploit parallel trends between groups over time
  • Regression Discontinuity (RD): exploit discontinuous treatment assignment rules
  • Control function / Heckman correction: model the selection process directly



9. Difference-in-Differences (DID)

DID exploits variation across groups and over time to estimate causal effects. It requires panel data (or repeated cross-sections): observations on treatment and control groups both before and after the intervention.

Setup

Let \(t=0\) (pre-treatment) and \(t=1\) (post-treatment). Let \(D=1\) (treatment group) and \(D=0\) (control group). The DID estimator is:

\[ \hat{\beta}_{DID} = \left(\bar{Y}_{1,1} - \bar{Y}_{1,0}\right) - \left(\bar{Y}_{0,1} - \bar{Y}_{0,0}\right) \]

where \(\bar{Y}_{D,t}\) is the mean outcome for group \(D\) at time \(t\). Equivalently, in a regression framework:

\[ Y_{it} = \alpha + \beta_1 D_i + \beta_2 Post_t + \beta_{DID} (D_i \times Post_t) + \varepsilon_{it} \]

The coefficient \(\beta_{DID}\) on the interaction term is the causal effect of interest.

Extensions

  • Multiple time periods: event-study designs with leads and lags
  • Staggered treatment: different groups adopt treatment at different times (requires careful estimation — Goodman-Bacon decomposition, Callaway & Sant'Anna)
  • Triple differences (DDD): adds a third dimension to control for group-specific time trends



10. Matching

Matching methods construct a counterfactual by pairing each treated unit with one or more "similar" control units based on observed covariates \(X\). The goal is to approximate the conditions of a randomized experiment by comparing units that look alike on observables.

Under the Conditional Independence Assumption \((Y_0, Y_1) \perp D | X\), matching identifies the ATT:

\[ ATT = E\left[Y_1 - Y_0 | D=1\right] = E\left[E[Y|D=1, X] - E[Y|D=0, X] \,|\, D=1\right] \]

Nearest Neighbor Matching

For each treated unit \(i\), find the control unit \(j\) with the smallest distance \(\|X_i - X_j\|\) (Euclidean, Mahalanobis, or other metric). The matched estimator is:

\[ \hat{ATT}_{NN} = \frac{1}{N_1} \sum_{i: D_i=1} \left(Y_i - Y_{j(i)}\right) \]

Variants: matching with replacement, k-nearest neighbors, caliper matching (maximum allowed distance).

Stratification (Subclassification)

Divide the propensity score \(p(X) = Pr(D=1|X)\) into strata (e.g., quintiles). Within each stratum, treatment assignment is approximately random. Compute the treatment effect within each stratum and average across strata, weighted by the proportion of treated units:

\[ \hat{ATT}_{strat} = \sum_{s=1}^{S} \frac{N_{1s}}{N_1} \left(\bar{Y}_{1s} - \bar{Y}_{0s}\right) \]

Kernel Matching

Instead of selecting a single match, kernel matching uses a weighted average of all control units, with weights decreasing in the distance to the treated unit:

\[ \hat{Y}_{0i} = \frac{\sum_{j: D_j=0} K\left(\frac{p_i - p_j}{h}\right) Y_j}{\sum_{j: D_j=0} K\left(\frac{p_i - p_j}{h}\right)} \]

where \(K(\cdot)\) is a kernel function (Gaussian, Epanechnikov) and \(h\) is the bandwidth. This reduces variance compared to nearest-neighbor matching but introduces a bandwidth choice.




11. Regression Discontinuity Design (RDD)

RDD exploits situations where treatment assignment is determined by whether a "running variable" \(x\) crosses a known cutoff \(x^*\). Near the cutoff, units just above and just below are nearly identical — creating a local randomized experiment.

Sharp RDD

Treatment is a deterministic function of the running variable:

\[ D_i = \mathbf{1}(x_i \geq x^*) = \begin{cases} 1 & \text{if } x_i \geq x^* \\ 0 & \text{if } x_i < x^* \end{cases} \]

The causal effect at the cutoff is:

\[ \tau_{RD} = \lim_{x \downarrow x^*} E[Y|X=x] - \lim_{x \uparrow x^*} E[Y|X=x] \]

This is a local estimate: it identifies the treatment effect only for units at the threshold. Examples: scholarship effects at GPA cutoffs, electoral effects at 50% vote thresholds.

Fuzzy RDD

The cutoff strongly predicts treatment but does not perfectly determine it. The probability of treatment jumps at \(x^*\) but does not go from 0 to 1:

\[ \lim_{x \downarrow x^*} Pr(D=1|X=x) \neq \lim_{x \uparrow x^*} Pr(D=1|X=x) \]

The Fuzzy RD is estimated via instrumental variables, using the indicator \(\mathbf{1}(x_i \geq x^*)\) as an instrument for \(D_i\):

\[ \tau_{FRD} = \frac{\lim_{x \downarrow x^*} E[Y|X=x] - \lim_{x \uparrow x^*} E[Y|X=x]}{\lim_{x \downarrow x^*} E[D|X=x] - \lim_{x \uparrow x^*} E[D|X=x]} \]

This identifies a Local Average Treatment Effect (LATE) for compliers at the threshold.




12. Instrumental Variables (IV)

When the treatment \(D\) is endogenous (\(Cov(D, \varepsilon) \neq 0\)), we need an instrument \(Z\) that affects \(Y\) only through \(D\).

Assumptions

  1. Relevance: \(Cov(Z, D) \neq 0\) — the instrument must be correlated with the endogenous treatment. Testable via first-stage F-statistic (rule of thumb: F > 10).
  2. Exclusion restriction: \(Cov(Z, \varepsilon) = 0\) — the instrument affects \(Y\) only through \(D\), not directly. Not testable (requires theoretical justification).
  3. Independence: \(Z\) is as good as randomly assigned (no confounders of \(Z\) and \(Y\)).
  4. Monotonicity (for LATE): the instrument affects everyone in the same direction (no "defiers").

Two-Stage Least Squares (2SLS)

First stage: regress the endogenous variable on the instrument(s) and controls:

\[ D_i = \pi_0 + \pi_1 Z_i + X_i'\delta + \nu_i \]

Second stage: replace \(D_i\) with its predicted value \(\hat{D}_i\) in the structural equation:

\[ Y_i = \beta_0 + \beta_1 \hat{D}_i + X_i'\gamma + \varepsilon_i \]

The 2SLS estimator with a single instrument and no controls simplifies to the Wald estimator:

\[ \hat{\beta}_{IV} = \frac{Cov(Z, Y)}{Cov(Z, D)} = \frac{\text{Reduced form}}{\text{First stage}} \]

Classic Examples

  • Returns to schooling: use quarter of birth as an instrument for years of education (Angrist & Krueger, 1991)
  • Effect of military service on earnings: use draft lottery number as instrument (Angrist, 1990)
  • Effect of institutions on development: use settler mortality as instrument for institutional quality (Acemoglu et al., 2001)



13. Structural Models

A structural model specifies the data-generating process through a system of causal equations derived from economic theory. Unlike reduced-form approaches, structural models make explicit assumptions about the mechanisms connecting variables.

Causal Equations

A structural equation represents a causal mechanism, not merely a statistical association. For example:

\[ Y = f(X_1, X_2, \ldots, X_k, \varepsilon) \]

means that \(Y\) is generated by the variables \(X_1, \ldots, X_k\) and an unobserved shock \(\varepsilon\). This is fundamentally different from a predictive equation where \(Y\) is merely associated with the right-hand-side variables.

Key distinction: in a structural model, intervening on \(X_j\) (setting it to a value) changes \(Y\) according to the equation. In a predictive model, changing \(X_j\) may not change \(Y\) at all (if the correlation is driven by a confounder).

Prediction vs Explanation: The Stork Example

Consider the well-known spurious correlation: regions with more storks tend to have higher birth rates. A predictive model might find:

\[ \widehat{Births} = \alpha + \beta \cdot Storks + \varepsilon, \qquad \hat{\beta} > 0, \; R^2 > 0 \]

This model predicts well (knowing stork population improves prediction of births), but it does not explain anything causally. Culling storks would not reduce births.

The structural (causal) model recognizes that both variables are driven by a confounder — rural area size (or urbanization level):

  • Rural areas → more stork habitat → more storks
  • Rural areas → more traditional family structures → higher birth rates

The correct structural equations are:

\[ Storks = g(Rural, \nu_1) \]

\[ Births = h(Rural, \nu_2) \]

where \(Rural\) is the common cause. Conditioning on (or intervening on) storks has no causal effect on births.

This illustrates the fundamental limitation of prediction: a model that predicts well may be useless (or worse, misleading) for policy. Prediction answers "what will happen?" while explanation answers "what will happen if we do X?" — and these are very different questions.