{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Chapter 24: Panel Data and Fixed Effects\n",
        "**Economic question:** What can repeated observations teach us that a single cross-section cannot?\n",
        "\nFixed effects use within-entity variation to remove time-invariant unobserved heterogeneity.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np, pandas as pd, statsmodels.formula.api as smf\n",
        "rng=np.random.default_rng(24); n,t=30,8\n",
        "id=np.repeat(np.arange(n),t); year=np.tile(np.arange(t),n); a=rng.normal(0,2,n)\n",
        "x=rng.normal(size=n*t); y=a[id]+.7*x+.2*year+rng.normal(size=n*t)\n",
        "df=pd.DataFrame({'y':y,'x':x,'id':id,'year':year})\n",
        "fit=smf.ols('y ~ x + C(id) + C(year)',data=df).fit(cov_type='cluster',cov_kwds={'groups':df['id']})\n",
        "print(fit.params['x'], fit.bse['x'])\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": 24,
      "source_origin": "supplied"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
