# Using feasible generalised least squares, is it possible to use OLS residuals to get a covariance matrix estimate?

I was fitting a model to some potentially autocorrelated and/or heteroskedastic data using feasible generalised least squares (FGLS). That is, I estimate coefficients by $$\widehat \beta_{FGLS} = (X'\Omega^{-1} X)^{-1} X' \Omega^{-1} y,$$ where $X$ is my design matrix. The weighting matrix/covariance matrix $\Omega$ is generally unknown, so it has to be estimated somehow. For modelling heteroskedasticity, we have to specify

$$\widehat{\Omega} = \operatorname{diag}(\widehat{\sigma}^2_1, \widehat{\sigma}^2_2, \dots , \widehat{\sigma}^2_n),$$

according to some model for the variance terms $\widehat{\sigma}^2_i$.

Now I read on Wikipedia the following: "It is important to notice that the squared residuals cannot be used in the previous expression; we need an estimator of the errors variances. To do so, we can use a parametric heteroskedasticity model, or a nonparametric estimator." -- https://en.wikipedia.org/wiki/Generalized_least_squares

However, when I have the OLS estimates $$\widehat \beta_{OLS} = (X' X)^{-1} X' y,$$

and estimates of the residuals $$\widehat{e}_j= (y-X\widehat\beta_{OLS})_j,$$ I wonder why would it not be possible to specify $$\widehat{\Omega} = \operatorname{diag}(\widehat{e}^2_1, \widehat{e}^2_2, \dots , \widehat{e}^2_n).$$

Am I wrong? Is Wikipedia wrong?

NB: seeing for example MATLAB's documentation of fgls (http://nl.mathworks.com/help/econ/fgls.html#namevaluepairs) we see that specifying 'innovMdl','HC0' as an option actually specifies the above residual-based covariance matrix. Also, when I test it, it works!

For autocorrelation consistent estimates, that's another matter entirely I guess (and consequently, MATLAB only provides autoregressive covariance matrix estimates).

• If your model is multivariate (more than one equation), isn't taking the OLS-based covariance matrix as $\Omega$ the standard textbook example of feasible GLS? I would consult Hayashi "Econometrics" (textbook), you might find an answer there. – Richard Hardy Nov 4 '16 at 20:06
• I read multiple text book entries on (W)GLS, and they seem to indicate that it is customary to specify a model for the variance. This is often done in examples as well. However, I believe that for heteroskedasticity it is allowed to use the squared OLS residuals to construct the covariance matrix. For auto/serialcorrelation however I think this is not possible. – Nick Nov 4 '16 at 21:51
• I think the concept of why this is so is similar as doing the other thing that's often done to handle these kind of data: updating the standard errors. When calculating heteroskedasticity consistent standard errors (i.e. Huber–White) you can just plug in the residuals. But when you want to model autocorrelation consistent standard errors you have to compute them using a Newey–West estimator. – Nick Nov 4 '16 at 21:51
• Do you have one equation or a system of equations? I am used to thinking about feasible GLS in systems of equations, not so much in single-equation settings. By the way, I find the Wikipedia article unclear at the point that you are citing... – Richard Hardy Nov 5 '16 at 7:13
• I am just talking about the standard case where you have a single equation (but multiple independent variables). I have little experience with multiple equations (i.e. multiple dependent variables). Note: to not confuse ourselves, in the context of M-estimators or GMM you also often talk about about 'equations' (i.e. plural) to mean the score equations for a likelihood analysis, even when you only have one dependent variable. – Nick Nov 6 '16 at 19:13