{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Applied Inference Project\n",
        "\n",
        "Learning goal: run a real multiple-regression inference workflow and write a careful interpretation.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Dataset check\n",
        "This cell confirms that the dataset file is available. If the file is missing, the notebook gives a safe warning rather than fake results.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import os\n",
        "DATASET = \"WAGE1.DTA\"\n",
        "VARIABLES = ['lwage', 'educ', 'exper', 'tenure']\n",
        "if not os.path.exists(DATASET):\n",
        "    raise FileNotFoundError(\n",
        "        \"Dataset file not installed yet\\n\"\n",
        "        \"Dataset: WAGE1\\n\"\n",
        "        \"Variables needed: lwage, educ, exper, tenure\\n\"\n",
        "        \"Course data folder: https://drive.google.com/drive/folders/1_STdcydIcst-opcbwOKRFzUXsgxQgBoS?usp=sharing\\n\"\n",
        "        \"Admin upload instruction: upload the dataset in Admin -> Datasets, publish it, and make the file available to the notebook runner.\"\n",
        "    )\n",
        "print(\"Ready:\", DATASET)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Estimate the model\n",
        "Estimate OLS and inspect the coefficient, standard error, t statistic, and p-value.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import pandas as pd\n",
        "import statsmodels.api as sm\n",
        "from scipy import stats\n",
        "\n",
        "df = pd.read_stata(DATASET)[VARIABLES].dropna()\n",
        "y = df[\"lwage\"]\n",
        "X = sm.add_constant(df[['educ', 'exper', 'tenure']])\n",
        "model = sm.OLS(y, X).fit()\n",
        "print(model.summary())\n",
        "print(\"Focus coefficient:\", \"educ\", model.params[\"educ\"])\n",
        "print(\"Standard error:\", model.bse[\"educ\"])\n",
        "print(\"t statistic:\", model.tvalues[\"educ\"])\n",
        "print(\"two-sided p-value:\", model.pvalues[\"educ\"])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Inference calculation\n",
        "Compute the lesson-specific inference object and connect it to the hypothesis.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "table = pd.DataFrame({\n",
        "    \"coef\": model.params,\n",
        "    \"std_err\": model.bse,\n",
        "    \"t\": model.tvalues,\n",
        "    \"p_value\": model.pvalues,\n",
        "})\n",
        "print(table)\n",
        "print(\"Draft report sentence: Holding the included controls fixed, interpret the focus coefficient with its uncertainty and a limitation.\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Check your understanding\n",
        "Write one sentence that distinguishes statistical significance from practical importance for this model.\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python (Pyodide)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "pygments_lexer": "ipython3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}