{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Reporting Regression Results\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 = \"CEOSAL2.DTA\"\n",
        "VARIABLES = ['lsalary', 'lsales', 'lmktval', 'ceoten']\n",
        "if not os.path.exists(DATASET):\n",
        "    raise FileNotFoundError(\n",
        "        \"Dataset file not installed yet\\n\"\n",
        "        \"Dataset: CEOSAL2\\n\"\n",
        "        \"Variables needed: lsalary, lsales, lmktval, ceoten\\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[\"lsalary\"]\n",
        "X = sm.add_constant(df[['lsales', 'lmktval', 'ceoten']])\n",
        "model = sm.OLS(y, X).fit()\n",
        "print(model.summary())\n",
        "print(\"Focus coefficient:\", \"ceoten\", model.params[\"ceoten\"])\n",
        "print(\"Standard error:\", model.bse[\"ceoten\"])\n",
        "print(\"t statistic:\", model.tvalues[\"ceoten\"])\n",
        "print(\"two-sided p-value:\", model.pvalues[\"ceoten\"])\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
}