# LPM Robust Inference
# Module 8 - The Linear Probability Model Revisited
# Dataset: MODULE8_BINARY_OUTCOME_LPM

# LPM Robust Inference
#
# Module 8 notebook lab. This notebook uses original Ceteris Lab teaching data and does not report real empirical findings.

# Learning goal
# Estimate a linear probability model with HC1 robust standard errors.
#
# Dataset: MODULE8_BINARY_OUTCOME_LPM. Variables: person_id, success, income, education, age, support_program.

# %% Cell 3
import pandas as pd
import statsmodels.api as sm

df = pd.read_csv("/data/module-8/module8_binary_outcome_lpm.csv")
X = sm.add_constant(df[["income", "education", "age", "support_program"]])
lpm = sm.OLS(df["success"], X).fit(cov_type="HC1")
fitted = lpm.fittedvalues
print(lpm.params.round(4))
print("Fitted probability range:", round(fitted.min(), 4), round(fitted.max(), 4))
print("Approximate variance p(1-p), first rows:")
print((fitted * (1 - fitted)).head().round(4))

# Reflection
# Write two sentences: one sentence explaining what the diagnostic or robust result says, and one sentence explaining a limitation or next step.
