University
Teaching materials · Econometric methods · MSc

Weighted least squares:tutorial exercises with full solutions

From ECON61001 Econometric Methods, University of Manchester (postgraduate).

Three worked exercises on weighted least squares under heteroskedasticity: deriving the estimator, proving when it is unbiased, measuring its efficiency gain over OLS with numbers, and choosing the weights when the variance pattern is known.

When the error variance differs across observations, OLS stays unbiased but is no longer the best linear unbiased estimator. Weighted least squares gives each squared residual a weight, so that noisier observations can count for less; with weights equal to the inverse of each error variance it is GLS, which is best. Three exercises with full solutions.

What these exercises cover

The exercises

When the error variance differs from one observation to the next (heteroskedasticity), the observations are not equally informative about the regression line: an observation whose error has variance 9 tells us less than one whose error has variance 1. OLS ignores this and gives every squared residual the same weight. Weighted least squares (WLS) gives each squared residual its own weight, so that the noisier observations count for less, and with weights equal to the inverse of each error variance it is the best linear unbiased estimator. Work each exercise on paper before opening its solution.

Exercise 1 · Deriving the WLS estimator

The linear model is \(y=X\beta+u\), with \(T\) observations on \(k\) regressors, \(E[u\mid X]=0\) and \(\operatorname{Var}(u\mid X)=\Sigma=\operatorname{diag}(\sigma_1^2,\dots,\sigma_T^2)\): the errors are uncorrelated, but their variances differ across observations. Row \(t\) of \(X\) is \(x_t'\). Weighted least squares chooses the coefficient vector to minimise a weighted sum of squared residuals, in which observation \(t\) carries a weight \(w_t>0\) that depends on \(X\) only:

$$S_W(b)=\sum_{t=1}^{T}w_t\,(y_t-x_t'b)^2.$$

(a) Write \(S_W(b)\) in matrix form and derive the WLS estimator \(\hat\beta_W\). What condition on \(X\) guarantees that it exists? (b) Show that \(\hat\beta_W\) is the OLS estimator in the regression of \(\sqrt{w_t}\,y_t\) on \(\sqrt{w_t}\,x_t\).

Solution to exercise 1

(a) The estimator. Collect the weights in the diagonal matrix \(W=\operatorname{diag}(w_1,\dots,w_T)\). The residual vector is \(y-Xb\), and the quadratic form with \(W\) in the middle multiplies each squared residual by its weight:

$$\begin{aligned}S_W(b)&=(y-Xb)'W(y-Xb)\\&=y'Wy-2b'X'Wy\\&\quad+b'X'WXb.\end{aligned}$$

(The two cross terms \(b'X'Wy\) and \(y'WXb\) are the same scalar, because \(W\) is symmetric.) \(S_W\) is a function of \(b\): for a given sample the data and the weights are fixed, and only \(b\) varies. Differentiating with respect to \(b\) and setting the result to zero,

$$\frac{\partial S_W}{\partial b}=-2X'Wy+2X'WXb=0,$$

that is, \(X'WX\,b=X'Wy\): the weighted normal equations. When \(X'WX\) is invertible they have one solution,

$$\hat\beta_W=(X'WX)^{-1}X'Wy.$$

\(X'WX\) is invertible when \(X\) has full column rank \(k\). For any vector \(c\neq0\), full rank gives \(Xc\neq0\), so \(c'X'WXc=\sum_t w_t(x_t'c)^2>0\) because every \(w_t>0\). So \(X'WX\) is positive definite, hence invertible; and since the second derivative of \(S_W\) is \(2X'WX\), the stationary point is the minimum. With every \(w_t=1\) the formula is the OLS estimator \((X'X)^{-1}X'y\).

(b) WLS is OLS on rescaled data. Let \(W^{1/2}=\operatorname{diag}(\sqrt{w_1},\dots,\sqrt{w_T})\), so that \(W^{1/2}W^{1/2}=W\) and \(W^{1/2}\) is symmetric. Define the rescaled data \(y^*=W^{1/2}y\) and \(X^*=W^{1/2}X\); row \(t\) of \(X^*\) is \(\sqrt{w_t}\,x_t'\). Then

$$X^{*\prime}X^*=X'W^{1/2}W^{1/2}X=X'WX,$$

$$X^{*\prime}y^*=X'W^{1/2}W^{1/2}y=X'Wy,$$

so OLS on the rescaled data is

$$\begin{aligned}&(X^{*\prime}X^*)^{-1}X^{*\prime}y^*\\&\quad=(X'WX)^{-1}X'Wy=\hat\beta_W.\end{aligned}$$

The reason is visible in the criterion itself: \(S_W(b)=\sum_t(\sqrt{w_t}\,y_t-\sqrt{w_t}\,x_t'b)^2\) is the ordinary sum of squared residuals of the rescaled regression. Two practical points follow. Any OLS routine computes WLS when it is given the rescaled data. And a column of ones in \(X\) becomes the column \(\sqrt{w_t}\) in \(X^*\), so the rescaled regression has no constant of its own: the original intercept is the coefficient on \(\sqrt{w_t}\).

Exercise 2 · Unbiasedness, the variance and the choice of weights

Keep the model and the estimator of Exercise 1.

(a) Show that \(E[\hat\beta_W\mid X]=\beta\) for any weights that are functions of \(X\) only. (b) Explain why the argument breaks down if the weights depend on \(y\). (c) Derive \(\operatorname{Var}(\hat\beta_W\mid X)\). Show that the weights \(w_t=1/\sigma_t^2\) give the GLS estimator \((X'\Sigma^{-1}X)^{-1}X'\Sigma^{-1}y\), and explain why it has the smallest variance among linear unbiased estimators. (d) A regression through the origin, \(y_t=\beta x_t+u_t\), has four observations with \(x=(1,2,3,4)\) and \(\sigma_t^2=(1,1,9,9)\). Compute \(\operatorname{Var}(\hat\beta_{OLS}\mid X)\) and \(\operatorname{Var}(\hat\beta_{GLS}\mid X)\), and the efficiency gain.

Solution to exercise 2

(a) Unbiasedness. Substitute the model \(y=X\beta+u\) into the formula:

$$\begin{aligned}\hat\beta_W&=(X'WX)^{-1}X'W(X\beta+u)\\&=\beta+(X'WX)^{-1}X'Wu.\end{aligned}$$

Write \(A=(X'WX)^{-1}X'W\). Because the weights depend on \(X\) only, \(A\) is fixed once we condition on \(X\), and it comes outside the expectation:

$$E[\hat\beta_W\mid X]=\beta+A\,E[u\mid X]=\beta,$$

using \(E[u\mid X]=0\). The weights enter only through \(A\), so the argument holds for any weights that are functions of \(X\); OLS, with every \(w_t=1\), is one case. Unbiasedness rests on the conditional mean of the errors, not on their variances.

(b) Weights that depend on \(y\). If \(w_t\) depends on \(y_t=x_t'\beta+u_t\), then \(W\), and with it \(A\), depends on \(u\). The bias term \(E[Au\mid X]\) is then the expectation of a product of two correlated random quantities, and it no longer factors into \(A\,E[u\mid X]=0\). For example, with \(w_t=1/y_t^2\), \(x_t>0\) and \(\beta>0\), an observation with a large positive error has a large \(y_t\) and so a small weight, while one with a negative error is weighted up: the estimate is pulled downwards.

(c) The variance, and the best weights. Given \(X\), \(\hat\beta_W-\beta=Au\), so

$$\begin{aligned}&\operatorname{Var}(\hat\beta_W\mid X)\\&=A\,\operatorname{Var}(u\mid X)\,A'\\&=(X'WX)^{-1}\\&\quad X'W\Sigma WX(X'WX)^{-1}.\end{aligned}$$

This "sandwich" holds for any weights that depend on \(X\) only. With \(w_t=1/\sigma_t^2\) we have \(W=\Sigma^{-1}\), and the estimator is GLS:

$$\hat\beta_{GLS}=(X'\Sigma^{-1}X)^{-1}X'\Sigma^{-1}y.$$

Since \(W\Sigma W=\Sigma^{-1}\Sigma\Sigma^{-1}=\Sigma^{-1}\), the sandwich collapses:

$$\operatorname{Var}(\hat\beta_{GLS}\mid X)=(X'\Sigma^{-1}X)^{-1}.$$

Why these weights are the best: with them, the rescaled model of Exercise 1(b) is \(y_t/\sigma_t=(x_t/\sigma_t)'\beta+u_t/\sigma_t\). Its error has conditional mean zero, the errors stay uncorrelated, and \(\operatorname{Var}(u_t/\sigma_t\mid X)=\sigma_t^2/\sigma_t^2=1\) for every \(t\). The rescaled model therefore satisfies the Gauss-Markov assumptions, and OLS on it, which is GLS, is the best linear unbiased estimator: any other estimator that is linear in \(y\) and conditionally unbiased has a variance at least as large, in the matrix sense. (Linear in the rescaled \(y_t/\sigma_t\) and linear in \(y\) are the same thing, since one is a fixed rescaling of the other.) Intuitively, the weight \(1/\sigma_t^2\) gives each observation influence in proportion to its precision.

(d) Four observations. Through the origin, \(X\) is the single column \(x\), and \(\sum_t x_t^2=1+4+9+16=30\). OLS is \(\hat\beta_{OLS}=\sum_t x_ty_t/\sum_t x_t^2\), and the sandwich with \(W=I\) gives

$$\begin{aligned}\operatorname{Var}(\hat\beta_{OLS}\mid X)&=\frac{\sum_t x_t^2\sigma_t^2}{\big(\sum_t x_t^2\big)^2}\\&=\frac{1+4+81+144}{30^2}\\&=\frac{230}{900}\\&\quad=\frac{23}{90}\approx0.256.\end{aligned}$$

(The textbook formula \(\sigma^2/\sum_t x_t^2\) does not apply here: it assumes one common variance \(\sigma^2\).) GLS uses the weights \(w_t=1/\sigma_t^2=(1,1,\tfrac19,\tfrac19)\), so \(\hat\beta_{GLS}=\sum_t w_tx_ty_t/\sum_t w_tx_t^2\), and

$$\begin{aligned}&\operatorname{Var}(\hat\beta_{GLS}\mid X)\\&\quad=\frac{1}{\sum_t x_t^2/\sigma_t^2}=\frac{1}{1+4+1+\tfrac{16}{9}}\\&\quad=\frac{9}{70}\approx0.129.\end{aligned}$$

The ratio is \(\tfrac{9}{70}\big/\tfrac{23}{90}=\tfrac{81}{161}\approx0.503\): GLS has about half the variance of OLS, and a standard error 29% smaller (\(\sqrt{0.503}\approx0.71\)). The gain comes from the last two observations: they have the largest values of \(x\), on which OLS leans hardest, and they are also the noisiest, with an error standard deviation of 3 against 1.

Exercise 3 · A known variance pattern, and the wrong weights

Household food spending \(y_t\) is regressed on income \(x_{1t}>0\) and household size \(x_{2t}\): \(y_t=\beta_0+\beta_1x_{1t}+\beta_2x_{2t}+u_t\), with \(E[u\mid X]=0\) and uncorrelated errors. Suppose \(\operatorname{Var}(u_t\mid X)=\sigma^2x_{1t}^2\), so that spending is more spread out among high-income households.

(a) Write down a transformed regression whose error is homoskedastic, and say where \(\beta_0\), \(\beta_1\) and \(\beta_2\) appear in it. (b) Which estimator is BLUE, and why? (c) A researcher believes instead that the variance is proportional to \(x_{1t}\), and uses WLS with \(w_t=1/x_{1t}\). Is the estimator unbiased? Is it efficient? Can its reported standard errors be trusted? (d) For a regression through the origin with \(x=(1,2,3,4)\) and \(\operatorname{Var}(u_t\mid X)=\sigma^2x_t^2\), compare the variances of OLS, of WLS with \(w_t=1/x_t\), and of GLS.

Solution to exercise 3

(a) The transformed regression. The error standard deviation is \(\sigma x_{1t}\), so dividing every term by \(x_{1t}\) (positive, so no sign changes) removes the pattern:

$$\frac{y_t}{x_{1t}}=\beta_0\,\frac{1}{x_{1t}}+\beta_1+\beta_2\,\frac{x_{2t}}{x_{1t}}+v_t,$$

with \(v_t=u_t/x_{1t}\).

The new error has \(E[v_t\mid X]=0\), the \(v_t\) stay uncorrelated, and \(\operatorname{Var}(v_t\mid X)=\sigma^2x_{1t}^2/x_{1t}^2=\sigma^2\), the same for every \(t\). The roles swap: the income slope \(\beta_1\) is now the constant of the transformed regression, and the original constant \(\beta_0\) is the coefficient on \(1/x_{1t}\). Read the output with that in mind.

(b) The BLUE. OLS on the transformed regression. It is WLS with \(w_t=1/x_{1t}^2\), which is proportional to \(1/\sigma_t^2=1/(\sigma^2x_{1t}^2)\); a constant factor in the weights cancels from \((X'WX)^{-1}X'Wy\), so we do not need to know \(\sigma^2\). By Exercise 2(c) this is GLS, and the transformed model satisfies the Gauss-Markov assumptions, so it is the best linear unbiased estimator.

(c) The wrong weights. The weights \(1/x_{1t}\) are functions of \(X\) only, so by Exercise 2(a) the estimator is unbiased. It is not efficient: its variance is the sandwich of Exercise 2(c), which that exercise shows is at least as large as \((X'\Sigma^{-1}X)^{-1}\) in the matrix sense, and strictly larger in the case worked in part (d). And the standard errors that the weighted regression prints are wrong. They are computed as if the weights had made the errors homoskedastic, which they have not: the rescaled error \(u_t/\sqrt{x_{1t}}\) has variance \(\sigma^2x_{1t}\), which still rises with income. Heteroskedasticity-robust standard errors, computed from the sandwich with squared residuals in place of \(\sigma_t^2\), give valid inference in large samples, though they do not restore the efficiency.

(d) Numbers. With \(\sigma_t^2=\sigma^2x_t^2\) and \(x=(1,2,3,4)\), the sandwich formula gives, in units of \(\sigma^2\):

  • OLS: \(\sum_t x_t^4/\big(\sum_t x_t^2\big)^2\), which is \((1+16+81+256)/30^2\), or \(354/900\approx0.393\).
  • WLS with \(w_t=1/x_t\): the estimator is \(\sum_t y_t/\sum_t x_t\), the ratio of the totals, with variance \(\sum_t x_t^2/\big(\sum_t x_t\big)^2\), which is \(30/10^2=0.30\).
  • GLS with \(w_t=1/x_t^2\): the estimator is the average of the ratios \(y_t/x_t\), with variance \(1/T=1/4=0.25\).

The wrong weights still beat OLS here, but their variance is 20% above that of GLS (\(0.30/0.25=1.2\)), and the variance of OLS is 57% above it (\(0.393/0.25\approx1.57\)).

A wrong weight pattern is not a wrong model. The weights decide only how the observations are combined. As long as they depend on \(X\) alone and \(E[u\mid X]=0\) holds, every choice of weights gives unbiased coefficients; what a poor choice costs is precision and, unless robust standard errors are used, valid inference. A misspecified mean, \(E[u\mid X]\neq0\), is a different and more serious problem, and no choice of weights repairs it.

What students say

“Nicky is an excellent econometrics tutor. He explains complex concepts clearly and makes them much easier to understand.”
Charles GardnerGoogle review
“I was completely lost in my economics class, and then I started working Nicky and he totally saved me. He was excellent at explaining the material and extremely accommodating to meet with me many times despite us being in different time zones! Highly recommend working with Nicky!”
Claire ChouGoogle review
“Nicky is a very good and thorough teacher. He has excellent knowledge of econometrics and takes the time to work through your questions. Highly recommended!”
ChrisEconometrics · 22/08
“Really great tutor! Encouraging, knowledgeable, friendly”
JedEconometrics · 09/02
“Very good lesson, Nicky is very helpful.”
ChrisEconometrics · 19/08
“Very helpful and clear.”
ClaireEconometrics · 22/01
“I gather it was very useful, thank you!”
ClaireEconometrics · 12/01
“Fantastic!”
JedEconometrics · 11/02

Who this is for

MSc and advanced undergraduate students practising estimator derivations and proof-style questions of the kind that appear in econometrics exams.

Related free resources

One-to-one help

For help with this material, or the module it belongs to, see econometrics tuition or university economics tuition. The first consultation is free, with no obligation.

Free worked video lectures: @unientryTMUA on YouTube.

Related tuition

Need help with this topic?

For one-to-one help, choose the closest subject below or send a short enquiry with your level, topic and deadline.

Book consultation View all tutoring subjects

Free 30-min consultationNo obligation · reply within one business day
Book now