Skip to main content

GLS / FGLS — Generalized Least Squares

GLS (Generalized Least Squares) generalizes OLS to handle heteroskedasticity and/or autocorrelation through the error covariance matrix Ω\Omega. When Ω\Omega is unknown and must be estimated from data, we use FGLS (Feasible GLS).

When to use

Use GLS/FGLS when errors have a complex variance/correlation structure (e.g., AR(1) autocorrelation, grouping). WLS is the special case of GLS when Ω\Omega is diagonal.


Model specification

GLS estimates:

β^GLS=(XΩ1X)1XΩ1Y\hat{\beta}_{GLS} = (X' \Omega^{-1} X)^{-1} X' \Omega^{-1} Y

where Ω=Var(εX)\Omega = \mathrm{Var}(\varepsilon \mid X) is the error covariance matrix. If Ω=σ2I\Omega = \sigma^2 I, GLS reduces to OLS.


GLS vs FGLS

GLSFGLS
Ω\OmegaKnownEstimated from data
PropertyEfficient (if Ω\Omega correct)Asymptotically efficient (large sample)
In practiceRarely know Ω\OmegaMore common

Running in EcoLab

  1. Modeling module → Classical linear regression family → GLS or FGLS.
  2. Select YY, the XX variables, and the covariance structure (e.g., AR(1), grouping).
  3. Run and read the Estimation and Diagnostics tabs; export the replication code.

Replication code

* ---- GLS / FGLS ----
* Load panel data (illustrative)
use "panel_data.dta", clear
xtset id time

* FGLS with heteroskedastic panels and AR(1) correlation
xtgls y x1 x2, panels(hetero) corr(ar1)

Limitations

  • FGLS can be biased in small samples if Ω\Omega is poorly estimated.
  • If you only need robust inference, OLS + robust/clustered standard errors is often simpler and safer.

Video tutorial

Video Tutorial: Running GLS in EcoLab

See also