Skip to main content

WLS — Weighted Least Squares

WLS (Weighted Least Squares) is a variant of OLS used when there is heteroskedasticity whose structure is known (or can be estimated). WLS assigns weights inversely proportional to the error variance to restore estimation efficiency.

When to use

Use WLS when the error variance is non-constant but has a known structure (e.g., variance proportional to a variable). If you only need robust inference without knowing the structure, use OLS + robust standard errors.


Model specification

WLS minimizes the weighted sum of squared residuals with weights wiw_i:

minβi=1nwi(YiXiβ)2,wi=1σi2\min_{\beta} \sum_{i=1}^{n} w_i \, (Y_i - X_i \beta)^2, \qquad w_i = \frac{1}{\sigma_i^2}

The optimal weight is the inverse of the error variance σi2\sigma_i^2. When all wiw_i are equal, WLS reduces to OLS.


Assumptions & notes

  • You must know or correctly estimate the variance structure σi2\sigma_i^2; wrong weights can make results worse than OLS.
  • If the variance must be estimated from data, you have FGLS (Feasible GLS).
  • Still requires exogeneity (E[εX]=0E[\varepsilon \mid X] = 0) as in OLS.

Running in EcoLab

  1. Modeling module → Classical linear regression family → WLS.
  2. Select YY, the XX variables, and the weight variable/rule (e.g., 1/x1/x, 1/x21/x^2).
  3. Run and compare with OLS in the Estimation tab; export the replication code.

Input / output example

Input (illustrative): household spending on income; variance grows with income ⇒ weights 1/income1/\text{income}.

Output (format, illustrative figures — not real results): coefficients similar to OLS but with smaller SE (more efficient) when the weights are correct.


Replication code

* ---- WLS: Weighted Least Squares ----
* Load data (illustrative)
use "household_data.dta", clear

* WLS with analytical weights (weight = 1/income)
regress spending x1 x2 [aweight=w]

* Compare with OLS
regress spending x1 x2

Limitations

  • Very sensitive to incorrect weight choice.
  • When unsure about the variance structure, prefer OLS + robust SE or GLS/FGLS.

Video tutorial

Video Tutorial: Running WLS in EcoLab

See also