skills/43-wentorai-research-plugins/skills/analysis/econometrics/econml-causal-guide/SKILL.md
Apply EconML for causal inference combining machine learning and econometrics
npx skillsauth add brycewang-stanford/Awesome-Agent-Skills-for-Empirical-Research econml-causal-guideInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
EconML is a Python package developed by Microsoft Research as part of the ALICE (Automated Learning and Intelligence for Causation and Economics) project. It provides a comprehensive suite of methods for estimating heterogeneous treatment effects from observational data, bridging the gap between modern machine learning and classical econometric techniques for causal inference.
Traditional econometric approaches to causal inference often rely on strong parametric assumptions and struggle with high-dimensional data. Pure machine learning methods excel at prediction but do not inherently distinguish correlation from causation. EconML combines the strengths of both paradigms, offering methods that leverage the flexibility of ML for nuisance parameter estimation while maintaining the rigorous causal identification guarantees of econometric theory.
The library implements cutting-edge methods from the academic literature including Double Machine Learning (DML), Causal Forests, Doubly Robust Learners, Orthogonal Random Forests, and Instrumental Variable methods with ML first stages. These tools are essential for researchers across economics, public health, education policy, and any field where understanding causal mechanisms from non-experimental data is critical.
Install EconML via pip:
pip install econml
For the full feature set including optional dependencies:
pip install econml[all]
EconML builds on top of scikit-learn and integrates with the broader Python data science ecosystem. Core dependencies include numpy, scipy, pandas, scikit-learn, and statsmodels. Optional dependencies for specific estimators include LightGBM and PyTorch.
Verify installation:
import econml
print(econml.__version__)
from econml.dml import LinearDML
from econml.orf import DMLOrthoForest
print("EconML loaded successfully")
Double Machine Learning (DML): The workhorse method for estimating average and heterogeneous treatment effects while controlling for high-dimensional confounders. DML uses cross-fitting and orthogonalization to eliminate regularization bias:
from econml.dml import LinearDML, CausalForestDML
from sklearn.ensemble import GradientBoostingRegressor
# Linear DML for parametric treatment effect estimation
est = LinearDML(
model_y=GradientBoostingRegressor(),
model_t=GradientBoostingRegressor(),
cv=5,
random_state=42
)
est.fit(Y, T, X=X, W=W)
# Get treatment effect estimates with confidence intervals
effect = est.effect(X_test)
ci = est.effect_interval(X_test, alpha=0.05)
print(f"ATE: {est.ate():.4f}")
print(f"ATE 95% CI: {est.ate_interval(alpha=0.05)}")
Here Y is the outcome, T is the treatment, X contains effect modifiers (features for heterogeneity), and W contains additional confounders.
Causal Forest DML: Combines DML orthogonalization with Causal Forest estimation for flexible, nonparametric heterogeneous treatment effects:
from econml.dml import CausalForestDML
cf_est = CausalForestDML(
model_y=GradientBoostingRegressor(),
model_t=GradientBoostingRegressor(),
n_estimators=200,
min_samples_leaf=10,
cv=5,
random_state=42
)
cf_est.fit(Y, T, X=X, W=W)
# Heterogeneous treatment effects
hte = cf_est.effect(X_test)
# Feature importance for treatment effect heterogeneity
importances = cf_est.feature_importances_
Doubly Robust Learner: Provides consistent treatment effect estimates when either the outcome model or the propensity score model is correctly specified:
from econml.dr import DRLearner
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor
dr_est = DRLearner(
model_propensity=RandomForestClassifier(),
model_regression=RandomForestRegressor(),
model_final=RandomForestRegressor(),
cv=5
)
dr_est.fit(Y, T, X=X, W=W)
Instrumental Variable Methods: For settings where unobserved confounding is present but valid instruments are available:
from econml.iv.dml import DMLIV
iv_est = DMLIV(
model_y_xw=GradientBoostingRegressor(),
model_t_xw=GradientBoostingRegressor(),
model_t_xwz=GradientBoostingRegressor(),
cv=5
)
iv_est.fit(Y, T, Z=Z, X=X, W=W)
Experiment Analysis: When randomized experiments suffer from non-compliance or attrition, use IV methods in EconML to recover local average treatment effects. The ML-based first stages handle complex relationships between instruments and treatment uptake.
Policy Evaluation: Estimate heterogeneous treatment effects to identify which subpopulations benefit most from an intervention. The CATE (Conditional Average Treatment Effect) estimates can directly inform targeted policy design:
# Identify subgroups with largest treatment effects
import pandas as pd
effects_df = pd.DataFrame({
"effect": cf_est.effect(X_test).flatten(),
"ci_lower": cf_est.effect_interval(X_test, alpha=0.05)[0].flatten(),
"ci_upper": cf_est.effect_interval(X_test, alpha=0.05)[1].flatten()
}, index=X_test.index)
# Top beneficiaries
top_group = effects_df.nlargest(100, "effect")
Sensitivity Analysis: Combine EconML estimates with sensitivity analysis frameworks to assess robustness to potential unobserved confounders. Report how much unmeasured confounding would be required to explain away your findings.
Publication-Ready Results: EconML provides confidence intervals and hypothesis tests based on asymptotic theory, producing results suitable for peer-reviewed publications. Use the summary methods to generate formatted regression-style output.
development
Conduct rigorous thematic analysis (TA) of qualitative data following Braun and Clarke's (2006) six-phase framework. Use whenever the user mentions 'thematic analysis', 'TA', 'Braun and Clarke', 'qualitative coding', 'identifying themes', or asks for help analysing interviews, focus groups, open-ended survey responses, or transcripts to identify patterns. Also trigger for questions about inductive vs theoretical coding, semantic vs latent themes, essentialist vs constructionist epistemology, building a thematic map, or writing up a qualitative findings section. Covers all six phases, the four upfront analytic decisions, the 15-point quality checklist, and the five common pitfalls. Produces a Word document write-up and an annotated thematic map. Does NOT cover IPA, grounded theory, discourse analysis, conversation analysis, or narrative analysis — use a different method for those.
development
Guide users through writing a systematic literature review (SLR) following the PRISMA 2020 framework. Use this skill whenever the user mentions 'systematic review', 'systematic literature review', 'SLR', 'PRISMA', 'PRISMA 2020', 'PRISMA flow diagram', 'PRISMA checklist', or asks for help writing, structuring, or auditing a literature review that follows reporting guidelines. Also trigger when the user asks about inclusion/exclusion criteria for a review, search strategies for databases like Scopus/WoS/PubMed, study selection processes, risk of bias assessment, or narrative synthesis for a review paper. This skill covers the full PRISMA 2020 checklist (27 items), produces a Word document manuscript in strict journal article format, generates an annotated PRISMA flow diagram, and enforces APA 7th Edition referencing throughout. It does NOT cover meta-analysis or statistical pooling. By Chuah Kee Man.
testing
Performs placebo-in-time sensitivity analysis with hierarchical null model and optional Bayesian assurance. Use when checking model robustness, verifying lack of pre-intervention effects, or estimating study power.
data-ai
Fit, summarize, plot, and interpret a chosen CausalPy experiment. Use after the causal method has been selected, including when configuring PyMC/sklearn models and scale-aware custom priors.