The most common question in causal inference is simple: On average, how much does a treatment change an outcome?
That quantity is called the Average Treatment Effect (ATE). In this example, we’ll estimate the ATE using DoWhy on the Lalonde dataset, a real-world dataset widely used to evaluate causal methods.
Step 1: Loading the Dataset
import pandas as pd from dowhy import CausalModel import dowhy.datasets # Load Lalonde dataset data = dowhy.datasets.lalonde_dataset() # Extract dataframe df = data["df"] # Preview data print(df.head())
What this does:
- Loads a real dataset from a job training program
- treatment: whether a person received training
- re78: earnings after the program, which is our outcome
- Other columns: age, education, prior income, and more
We will estimate how the training program affects earnings.
Step 2: Defining the Causal Model
model = CausalModel(
data=df,
treatment="treatment",
outcome="re78",
common_causes=[
"age", "educ", "black", "hisp",
"married", "nodegr", "re74", "re75"
]
)
What this does:
- Defines the treatment and outcome
- Specifies confounders that may affect both the treatment and the outcome
- Uses those assumptions to estimate a causal effect instead of a simple correlation
Step 3: Identifying the Average Treatment Effect Estimand
identified_estimand = model.identify_effect() print(identified_estimand)
What this does:
- Checks whether the ATE can be identified under the data and assumptions
- Typically returns a backdoor estimand, meaning we adjust for confounders
You don’t need to compute the formula manually. DoWhy derives it for you.
Step 4: Estimating the Average Treatment Effect
estimate = model.estimate_effect(
identified_estimand,
method_name="backdoor.linear_regression"
)
print(estimate.value)
What this does:
- Uses linear regression with backdoor adjustment
- Controls for all specified confounders
- Returns the ATE
How to Interpret the Average Treatment Effect
Suppose the output is: 1675.3
This means: On average, individuals who received the training program earned about $1,675 more than they would have without it.
That is the key idea behind the ATE. It does not describe one specific individual. It describes the average effect across the population.
Using a Different Estimator
DoWhy supports multiple estimation methods. For example, we can use propensity score matching:
estimate_psm = model.estimate_effect(
identified_estimand,
method_name="backdoor.propensity_score_matching"
)
print(estimate_psm.value)
What this does:
- Matches treated and untreated individuals with similar characteristics
- Computes the ATE based on those matched comparisons
Different methods may produce slightly different results, which is expected.
Conclusion
Estimating the ATE is straightforward once your assumptions are clear. You define the causal model, confirm that the effect is identifiable, and then compute the estimate using a method like regression or matching.
What matters is not just the number you get, but what it represents. The ATE answers a specific question: What is the average impact of this intervention if we applied it across the population?
