Before you estimate any causal effect, there is a more basic question: Can this effect even be computed from your data and assumptions?
That is what identification answers. Instead of manually deriving formulas, DoWhy can automatically determine whether a valid estimand exists and how to compute it. In this example, we’ll use the Lalonde dataset and focus only on identification.
Step 1: Load 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 print(df.head())
What this does:
- Loads a real dataset from a job training program
- Identifies treatment as participation in the training program
- Identifies re78 as earnings after the program
- Uses other columns as confounders, including age, education, and prior income
Step 2: Define the Causal Model
model = CausalModel(
data=df,
treatment="treatment",
outcome="re78",
common_causes=[
"age", "educ", "black", "hisp",
"married", "nodegr", "re74", "re75"
]
)
What this does:
- Specifies the treatment and outcome variables
- Declares confounders that may influence both the treatment and outcome
- Provides the structure DoWhy uses to reason about identification
Step 3: Automatically Identify the Estimand
identified_estimand = model.identify_effect() print(identified_estimand)
What this does:
- Runs DoWhy’s auto-identification step
- Checks whether the causal effect is identifiable
- Returns a formal representation of the estimand
What Is an Estimand?
An estimand is the mathematical expression that defines the causal effect you want to compute. In this case, DoWhy will typically return something based on backdoor adjustment, which means:
Adjust for confounders so you can isolate the effect of the treatment on the outcome.
You might see output that includes:
- The variables being conditioned on
- The type of identification strategy, such as backdoor adjustment
- A symbolic expression of the effect
Why Auto-Identification Matters
Without this step, you are guessing how to estimate the effect. With auto-identification:
- You know whether the effect is computable
- You know which variables must be controlled for
- You avoid using invalid estimation strategies
If the effect is not identifiable, DoWhy will tell you. That is a signal that your assumptions or available data are not sufficient.
Optional: View the Graph
You can also visualize the causal graph:
model.view_model()
What this does:
- Generates a directed acyclic graph (DAG) of your assumptions
- Helps you visually confirm the relationships between variables
Conclusion
Auto-identification is a checkpoint that many analyses skip. It forces you to answer a simple but critical question:
Do I have enough information to estimate this effect correctly?
With DoWhy, you do not need to derive formulas by hand. You define your assumptions, and the library tells you whether your causal question is valid and how to approach it.
