Back to rankings

jrfiedler/causal_inference_python_code

Jupyter Notebook

Python code for part 2 of the book Causal Inference: What If, by Miguel Hernán and James Robins

causalitycausal-inferencedata-sciencepython
Star Growth
Stars
1.4k
Forks
412
Weekly Growth
Issues
1
5001k
Feb 2018Nov 2020Sep 2023Jul 2026
README

Python Code for Causal Inference: What If

This repo contains Python code for Part II of the book Causal Inference: What If, by Miguel Hernán and James Robins (book site):

Hernán MA, Robins JM (2020). Causal Inference: What If. Boca Raton: Chapman & Hall/CRC.

This Python version roughly corresponds to the Stata, R, or SAS programs found at the book site, and was also translated into Julia, here.

The code in this repo has been checked against the 30 March 2021 version of the book.

Python dependencies

Required Python packages:

  • numpy
  • pandas
  • statsmodels
  • scipy
  • matplotlib
  • linearmodels
  • tqdm

If you use the Anaconda distribution of Python, you'll have most of those packages already, and you'll only need to install

  • linearmodels
  • tqdm

Data

The data can be obtained from the book site.

The notebooks all assume that the Excel version of the data has been saved in the same directory as the notebooks.

Author

James Fiedler, with contributions from Petty PY Chen and Piyush Madan

Related repositories
py-why/dowhy

DoWhy is a Python library for causal inference that supports explicit modeling and testing of causal assumptions. DoWhy is based on a unified language for causal inference, combining causal graphical models and potential outcomes frameworks.

PythonPyPIMIT Licensecausal-inferencemachine-learning
pywhy.org/dowhy
8.2k1k
py-why/EconML

ALICE (Automated Learning and Intelligence for Causation and Economics) is a Microsoft Research project aimed at applying Artificial Intelligence concepts to economic decision making. One of its goals is to build a toolkit that combines state-of-the-art machine learning techniques with econometrics in order to bring automation to complex causal inference problems. To date, the ALICE Python SDK (econml) implements orthogonal machine learning algorithms such as the double machine learning work of Chernozhukov et al. This toolkit is designed to measure the causal effect of some treatment variable(s) t on an outcome variable y, controlling for a set of features x.

Jupyter NotebookOthermachine-learningeconomics
microsoft.com/en-us/research/project/alice/
4.7k818
Kanaries/Rath

Next generation of automated data exploratory analysis and visualization platform.

TypeScriptnpmGNU Affero General Public License v3.0dataminingvisualization
rath.kanaries.net
4.7k384
matheusfacure/python-causality-handbook

Causal Inference for the Brave and True. A light-hearted yet rigorous approach to learning about impact estimation and causality.

Jupyter NotebookMIT Licensecausal-inferencepython
matheusfacure.github.io/python-causality-handbook/landing-page.html
3.4k613
rguo12/awesome-causality-algorithms

An index of algorithms for learning causality with data

MIT Licensecausalitycausal-inference
3.3k475
HCPLab-SYSU/Embodied_AI_Paper_List

[Embodied-AI-Survey-2025] Paper List and Resource Repository for Embodied AI

embodied-aiagent
2.1k147
py-why/causal-learn

Causal Discovery in Python. Learning causality from data.

PythonPyPIMIT Licensecausalcausal-discovery
causal-learn.readthedocs.io/en/latest/
1.7k268
yfzhang114/Generalization-Causality

关于domain generalization,domain adaptation,causality,robutness,prompt,optimization,generative model各式各样研究的阅读笔记

MIT Licensemachine-learningdeep-learning
1.2k102
FenTechSolutions/CausalDiscoveryToolbox

Package for causal inference in graphs and in the pairwise settings. Tools for graph structure recovery and dependencies are included.

PythonPyPIMIT Licensecausal-inferencegraph
fentechsolutions.github.io/CausalDiscoveryToolbox/html/index.html
1.2k201
itamarst/eliot

Eliot: the logging system that tells you *why* it happened

PythonPyPIApache License 2.0pythonlogging
eliot.readthedocs.io
1.2k74
huawei-noah/trustworthyAI

Trustworthy AI related projects

PythonPyPIApache License 2.0causal-discoverycausal-inference
1.1k249