WLS & Robust SE in Python

ECON 3209 · Week 12, Lecture 3 · Kerala Agricultural University

Department of Development Economics, KAU

Autumn 2026

Learning Outcomes

By the end of this lecture, you will be able to:

  1. distinguish robust standard errors from weighted least squares
  2. estimate HC3-robust standard errors in statsmodels
  3. fit a weighted least squares model when a variance pattern is known
  4. compare coefficient tables across OLS, robust OLS, and WLS
  5. decide which remedy fits a particular empirical problem

Two Main Responses to Heteroscedasticity

Robust standard errors

  • keep the OLS coefficients
  • correct the estimated uncertainty
  • easy default in many applied papers

Weighted Least Squares

  • change both coefficients and standard errors
  • give less weight to high-variance observations
  • useful when the variance model is well understood

HC3 Robust Standard Errors

HC3 is a popular heteroscedasticity-robust correction, especially in moderate samples.

It leaves \(\hat\beta\) unchanged but recomputes the covariance matrix.

In practice, robust SEs are often the safest first remedy when you do not trust the homoskedasticity assumption.

Weighted Least Squares

If \(Var(\varepsilon_i|X_i) \propto h_i\), use weights proportional to \(1/h_i\).

\[\min_{\beta} \sum_{i=1}^n w_i (Y_i - X_i'\beta)^2\]

with larger weights on observations having smaller error variance.

When Is WLS Sensible?

WLS is most useful when variance grows in a known way, such as: - variance proportional to farm size - sampling design weights - grouped data with known precision differences

If the variance model is wrong, WLS can mislead.

Python Demo: Baseline OLS

Python Demo: HC3 Robust Standard Errors

Python Demo: Weighted Least Squares

Python Demo: Compare OLS, HC3, and WLS

Python Demo: Visualize Weighted Fit

Decision Guide

  • If you only need valid inference: use robust SEs.
  • If you know the variance structure fairly well: consider WLS.
  • If heteroscedasticity comes from scale, try logs or respecification too.

Robust SEs fix the standard errors. WLS changes the estimation problem itself.

🏋️ Exercise

  1. Simulate income data with error variance increasing in wealth.
  2. Estimate OLS and then compute HC3 robust standard errors.
  3. Create weights equal to the inverse of the error variance.
  4. Estimate a WLS model and compare it with OLS.

Summary

✅ Robust standard errors leave OLS coefficients unchanged but repair inference under heteroscedasticity.

✅ HC3 is a useful default robust covariance choice in moderate samples.

✅ WLS reweights observations and can improve efficiency when the variance model is credible.

✅ Comparing OLS, robust OLS, and WLS reveals whether heteroscedasticity matters in practice.

✅ Method choice should follow the empirical goal and how much you know about the variance pattern.

Next Lecture

Week 13 — Dummy Variables

We will cover: - binary and categorical predictors - interaction terms - structural breaks - dummy-variable coding in Python