Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 36 ยท Regression

Regression Diagnostics and Robust Standard Errors

Check a Stata regression for heteroskedasticity, multicollinearity, outliers and misspecification with rvfplot, estat hettest, vif and robust or clustered errors.

Fitting a model takes one line; trusting it takes a few more. OLS gives unbiased estimates only under assumptions: the relationship is linear, errors have constant variance, observations are independent, and predictors are not nearly collinear. Stata ships with postestimation commands that check each one. This lesson walks through the most useful, shows what to do when a check fails, and ends with a runnable stand-in that demonstrates why robust standard errors matter.

Stata cannot run on this site. Commands appear in read-only blocks and we do not print Stata results. The Python stand-ins simulate data and compute the same statistics.

Look first: residual plots

Always plot before testing.

STATA
sysuse auto, clear
regress price mpg weight
rvfplot, yline(0)       // residuals versus fitted values
avplots                 // added-variable plots for each predictor
lvr2plot                // leverage versus squared residuals

In rvfplot, a healthy model shows a shapeless band around zero. A funnel shape means the error variance changes with the fitted value (heteroskedasticity). A curve means a missing nonlinear term. avplots shows the partial relationship of each predictor with the outcome after the others are removed, and helps you spot single influential points.

Tests for heteroskedasticity and misspecification

STATA
estat hettest               // Breusch-Pagan / Cook-Weisberg
estat imtest, white         // White's general test
estat ovtest                // Ramsey RESET for omitted powers
linktest                    // another specification check

Each reports a chi-squared or F statistic and a p-value. A small p-value rejects the null of constant variance (hettest, imtest) or of a correct functional form (ovtest, linktest). Statistical tests have power that grows with sample size, so with large samples they reject over trivial departures; combine them with the plots.

Multicollinearity

STATA
estat vif
correlate mpg weight length

The variance inflation factor shows how much the variance of a coefficient is inflated by correlation with the other predictors. Many analysts worry above 10 (or above 5 for a stricter rule), but treat that as a prompt to look, not a law. Collinearity does not bias coefficients; it only makes them imprecise. The fix is more data, dropping a redundant variable, or combining variables.

Influential observations

STATA
predict h, hat
predict cooksd, cooksd
predict dfb_mpg, dfbeta(mpg)
list make price if cooksd > 4/e(N) & e(sample)

A common rule flags Cook's distance above 4/N. Do not delete a point just because it is influential: check whether it is a data error, a different population, or an honest extreme. Report results with and without it if you are unsure.

Robust and clustered standard errors

When heteroskedasticity is present, the coefficients stay unbiased but the usual standard errors are wrong. The simplest remedy is Huber-White (robust) errors:

STATA
regress price mpg weight, vce(robust)
regress price mpg weight, vce(cluster state)
regress price mpg weight, vce(hc3)

vce(robust) changes only the standard errors, t statistics, p-values and intervals, not the coefficients. vce(cluster id) allows arbitrary correlation of errors within a group, for example students in one school or repeated rows for one person, and is essential with panel data. With few clusters (fewer than about 30-40) the cluster-robust errors can be too small, so be cautious.

Stand-in: why robust errors matter

This simulation makes the error variance grow with x. The classical standard error assumes constant variance; the robust one (the HC1 formula Stata uses for vce(robust)) allows it to vary. Repeating the experiment many times, we compare how often each 95% interval covers the true slope.

Python Classical vs robust standard errors (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The classical intervals cover the truth noticeably less often than 95%, while the robust ones come much closer. That is the practical case for vce(robust) whenever you suspect non-constant variance.

A quick VIF calculator

Variance inflation factors come from regressing each predictor on the others: VIF = 1 / (1 - R squared). The stand-in computes them for two nearly collinear variables.

Python VIF by hand (Python stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A sensible workflow

  1. Fit the model and read the output.
  2. Plot residuals; fix obvious nonlinearity with polynomials or logs (see factor variables).
  3. Test and compare, but trust plots and theory more than any single p-value.
  4. Report robust or clustered standard errors by default when observations are not obviously independent and identically distributed.
  5. Keep a record in a do-file so every check can be repeated.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a funnel shape in rvfplot suggest?

    Residual spread that widens or narrows with the fitted value signals non-constant error variance.
  2. 2. Which option changes standard errors but not coefficients?

    Robust and cluster-robust variance estimators correct the standard errors only; the OLS point estimates stay identical.
  3. 3. What does a high VIF tell you?

    Collinearity makes estimates imprecise rather than biased.
  4. 4. When should you use vce(cluster id)?

    Cluster-robust errors allow arbitrary within-group correlation, which is common with repeated observations.

Summary

  • Plot residuals first, then use estat hettest, estat imtest, estat ovtest and linktest.
  • estat vif flags collinearity; Cook's distance and dfbeta flag influential rows.
  • vce(robust) and vce(cluster id) repair standard errors without changing coefficients.
  • The Python blocks are labelled stand-ins that reproduce the statistics.

Next: Logit, probit and margins