{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Chapter 29: Difference-in-Differences and Event Studies\n",
        "**Economic question:** How can policy evaluation use changes over time when randomized assignment is unavailable?\n",
        "\nDifference-in-differences identifies a treatment effect from differential changes under a parallel-trends assumption.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd, statsmodels.formula.api as smf\n",
        "rows=[]\n",
        "for g in [0,1]:\n",
        "  for t in range(8):\n",
        "    for i in range(40): rows.append((g,t,10+.5*t+g+(3 if (g==1 and t>=4) else 0)))\n",
        "df=pd.DataFrame(rows,columns=['treated','time','y']); df['post']=(df.time>=4).astype(int)\n",
        "fit=smf.ols('y ~ treated * post + C(time)',data=df).fit()\n",
        "print('DID',fit.params['treated:post'])\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": 29,
      "source_origin": "supplied"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
