---
title: "Week 3: Oregon IV exercise"
subtitle: "PP5001 · Ungraded practice"
author: "Student ID: ..."
format:
  html:
    embed-resources: true
    code-fold: false
    toc: false
    html-math-method: katex
    include-in-header:
      text: |
        <style>
        @media print {
          @page { size: A4; margin: 15mm; }
          html, body { width: auto !important; min-width: 0 !important; }
          #quarto-content, main.content { display: block !important; width: 100% !important; max-width: 100% !important; min-width: 0 !important; margin: 0 !important; padding: 0 !important; }
          .cell, .cell-output, .cell-output-display, .table-responsive, .quarto-table-container { min-width: 0 !important; max-width: 100% !important; overflow: visible !important; }
          table { display: table !important; width: 100% !important; max-width: 100% !important; table-layout: fixed !important; border-collapse: collapse; font-size: 8.5pt !important; }
          th, td { min-width: 0 !important; width: auto !important; white-space: normal !important; overflow-wrap: anywhere !important; padding: 3pt !important; }
          thead { display: table-header-group; }
          tr { break-inside: avoid; }
          pre, pre code, pre code span { white-space: pre-wrap !important; overflow-wrap: anywhere !important; }
          pre { max-width: 100% !important; overflow: visible !important; font-size: 8pt; }
          img, svg { max-width: 100% !important; height: auto; }
          .code-copy-button, .anchorjs-link { display: none !important; }
        }
        </style>
execute:
  echo: true
  warning: true
  error: false
jupyter: python3
---

## Data and analysis sample

Download **PP5001-week-03-oregon-data.zip** from the Week 3 section of Moodle and unzip it. Save this document beside the extracted `data` and `documentation` folders. Read `documentation/ohie_userguide.pdf` for the study design and data documentation.

```{python}
from pathlib import Path
import pandas as pd
import statsmodels.formula.api as smf
import linearmodels.iv as iv

folder = Path("data")
descriptive = pd.read_stata(
    folder / "oregonhie_descriptive_vars.dta", convert_categoricals=False
)
enrolment = pd.read_stata(
    folder / "oregonhie_stateprograms_vars.dta", convert_categoricals=False
)
survey = pd.read_stata(
    folder / "oregonhie_survey12m_vars.dta", convert_categoricals=False
)

data = descriptive.merge(
    enrolment, on="person_id", validate="one_to_one"
).merge(survey, on="person_id", validate="one_to_one")
data = data.rename(columns={
    "treatment": "selected",
    "ohp_all_ever_firstn_30sep2009": "medicaid",
    "doc_any_12m": "outpatient",
})
needed = [
    "selected", "medicaid", "outpatient", "numhh_list",
    "wave_survey12m", "weight_12m", "household_id",
]
analysis = data.loc[
    (data["sample_12m_resp"] == 1) & (data["weight_12m"] > 0)
].dropna(subset=needed).copy()
analysis["stratum"] = (
    analysis["numhh_list"].astype(int).astype(str) + "_" +
    analysis["wave_survey12m"].astype(int).astype(str)
)
print(f"Analysis sample: {len(analysis):,} individuals")
```

## 1. Understand the comparison

Write your explanation here.

```{python}
# Add your code here.
```

## 2. First stage

Write your explanation here.

```{python}
# Add your code here.
```

## 3. Intention-to-treat effect

Write your explanation here.

```{python}
# Add your code here.
```

## 4. Instrumental variables

Write your explanation here.

```{python}
# Add your code here.
```

## 5. Compare and interpret

Write your explanation here.

```{python}
# Add your code here.
```

## 6. Critique Claude

Give Claude the following prompt:

> Explain what the Oregon Health Insurance Experiment tells us about the effects of Medicaid and what policymakers should learn from it. Write approximately 400 words for a Master of Public Policy student.

Include Claude’s response in your notebook. Then answer:

> Assess Claude’s explanation using the assigned paper and your estimates. Identify two claims that are well supported and two statements that require correction or qualification. Explain your reasoning and rewrite the latter statements.

Write your assessment here.
