{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Population and Group-Size Weights\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",
        "Use group size as a precision weight.\n",
        "\n",
        "Dataset: MODULE8_WLS_GROUP_MEANS. Variables: group_id, group_size, mean_outcome, mean_income, mean_education, population_weight.\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_wls_group_means.csv\")\n",
        "X = sm.add_constant(df[[\"mean_income\", \"mean_education\"]])\n",
        "unweighted = sm.OLS(df[\"mean_outcome\"], X).fit()\n",
        "weighted = sm.WLS(df[\"mean_outcome\"], X, weights=df[\"population_weight\"]).fit()\n",
        "print(pd.DataFrame({\"unweighted\": unweighted.params, \"population_weighted\": weighted.params}).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": "Group Means, Population Weights, and Aggregated Data",
      "dataset": "MODULE8_WLS_GROUP_MEANS",
      "copyright": "Original Ceteris Lab notebook. No external text, tables, or figures are reproduced."
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
