# LPM Robust Standard Errors
# Module 7 - Limitations of the Linear Probability Model
# Dataset: MODULE7_LOAN_APPROVAL_SYNTHETIC

# LPM Robust Standard Errors
#
# Module 7 notebook lab. This notebook uses an original Ceteris Lab synthetic teaching dataset and does not report real empirical findings.

# Learning goal
# Inspect fitted probabilities and use HC1 robust standard errors.
#
# Dataset: MODULE7_LOAN_APPROVAL_SYNTHETIC. Variables: approved, income, debt_ratio, credit_score.

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

df = pd.read_csv("/data/module-7/module7_loan_approval_synthetic.csv")
X = sm.add_constant(df[["income", "debt_ratio", "credit_score", "loan_to_value", "co_signer"]])
model = sm.OLS(df["approved"], X).fit(cov_type="HC1")
pred = model.predict(X)
print("Minimum fitted probability:", round(pred.min(), 3))
print("Maximum fitted probability:", round(pred.max(), 3))
print("Percent correctly predicted at 0.5:", round(((pred >= 0.5) == df["approved"]).mean() * 100, 1))

# Reflection
# Write two sentences: one coefficient, group difference, or predicted-probability interpretation, and one limitation or coding choice that matters.
