{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Chapter 34: Causal Machine Learning and Double Machine Learning\n",
        "**Economic question:** How can flexible prediction tools help estimate causal parameters without replacing identification assumptions?\n",
        "\nDouble machine learning uses prediction to remove nuisance structure while protecting a low-dimensional causal target through orthogonalization.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np, statsmodels.api as sm\n",
        "from sklearn.ensemble import RandomForestRegressor\n",
        "rng=np.random.default_rng(34); Z=rng.normal(size=(1000,6)); d=Z[:,0]-Z[:,1]+rng.normal(size=1000); y=2*d+Z[:,0]+.5*Z[:,2]+rng.normal(size=1000)\n",
        "md=RandomForestRegressor(n_estimators=200,random_state=1,min_samples_leaf=10).fit(Z,d); my=RandomForestRegressor(n_estimators=200,random_state=2,min_samples_leaf=10).fit(Z,y)\n",
        "rd=d-md.predict(Z); ry=y-my.predict(Z); print(sm.OLS(ry,sm.add_constant(rd)).fit().params[1])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Interpretation checklist\n",
        "- State the unit of observation and units of every variable.\n",
        "- Separate association, prediction, and causation.\n",
        "- Report magnitude and uncertainty.\n",
        "- Identify the most important threat to validity.\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.13"
    },
    "ceteris_lab": {
      "course_slug": "fundamentals-python-econometrics",
      "course_title": "Fundamentals of Python for Financial Econometrics",
      "chapter": 34,
      "source_origin": "supplied"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
