# Nonnormal Errors and Large-Sample Inference
# Module 5 - Large-Sample t and F Tests
# Dataset: 401K

# Nonnormal Errors and Large-Sample Inference
#
# Learning goal: Estimate a model with a nonnormal outcome and interpret large-sample inference.

# Dataset check
# This cell confirms the dataset file is available. Simulation notebooks mount a harmless CSV so public file delivery is still validated.

# %% Cell 3
import os
DATASET = "401K.csv"
VARIABLES = ["prate","mrate","age","totemp"]
if not os.path.exists(DATASET):
    raise FileNotFoundError(
        "Dataset file not installed yet\n"
        "Dataset: 401K\n"
        "Variables needed: prate, mrate, age, totemp\n"
        "Course data folder: https://drive.google.com/drive/folders/1_STdcydIcst-opcbwOKRFzUXsgxQgBoS?usp=sharing\n"
        "Admin upload instruction: upload the dataset in Admin -> Datasets, publish it, and make the file available to the notebook runner."
    )
print("Ready:", DATASET)

# Run the lab
# Run the code, inspect the table or graph, and connect the result to the formula in the lesson.

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

data = pd.read_csv("401K.csv")
data = data.dropna(subset=["prate", "mrate", "age", "totemp"])
X = sm.add_constant(data[["mrate", "age", "totemp"]])
model = sm.OLS(data["prate"], X).fit()
print(model.summary().tables[1])
print("Use large-sample logic carefully: prate is bounded and often nonnormal.")

# Formula explanation
# Explain the probability limit, asymptotic approximation, standard-error pattern, or LM statistic in words. Do not treat output as automatic causal evidence.

# Short exercise
# Change one sample size, regressor, or restriction. Write two sentences: what changed mechanically, and what assumption still matters?
#
# Check your understanding
# Does increasing n fix nonnormality, endogeneity, heteroskedasticity, or omitted variables? Explain.
