{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# LPM Robust Inference\n",
        "\n",
        "Module 8 notebook lab. This notebook uses original Ceteris Lab teaching data and does not report real empirical findings.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Learning goal\n",
        "Estimate a linear probability model with HC1 robust standard errors.\n",
        "\n",
        "Dataset: MODULE8_BINARY_OUTCOME_LPM. Variables: person_id, success, income, education, age, support_program.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd\n",
        "import statsmodels.api as sm\n",
        "\n",
        "df = pd.read_csv(\"/data/module-8/module8_binary_outcome_lpm.csv\")\n",
        "X = sm.add_constant(df[[\"income\", \"education\", \"age\", \"support_program\"]])\n",
        "lpm = sm.OLS(df[\"success\"], X).fit(cov_type=\"HC1\")\n",
        "fitted = lpm.fittedvalues\n",
        "print(lpm.params.round(4))\n",
        "print(\"Fitted probability range:\", round(fitted.min(), 4), round(fitted.max(), 4))\n",
        "print(\"Approximate variance p(1-p), first rows:\")\n",
        "print((fitted * (1 - fitted)).head().round(4))\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Reflection\n",
        "Write two sentences: one sentence explaining what the diagnostic or robust result says, and one sentence explaining a limitation or next step.\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.11"
    },
    "ceteris_lab": {
      "module": "Module 8",
      "lesson": "The Linear Probability Model Revisited",
      "dataset": "MODULE8_BINARY_OUTCOME_LPM",
      "copyright": "Original Ceteris Lab notebook. No external text, tables, or figures are reproduced."
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
