# What does it mean to "replace all variables with the residuals after projections on any additional exogenous regressors"

I am conducting IV Regression and to make sure that my instrument is not weak, I want to use Montiel Olea & Pflueger (2013) robustness test. (see: Paper by Montiel Olea & Plueger (2013) ). To do so, you need their stata ado "weakivtest", which is an post-regression command. However, in their paper they specify 4 steps how to conduct this test (without stata ado). The first steps says the following: If there are additional exogenous regressors, replace all variables by their projection residuals onto those exogenous regressors. Normalize instruments to be orthonormal. (see Montiel Olea & Pflueger, 2013: p.360).

How do I do that? Do I have to run a regression and simply use the residuals? Which regression to run: first stage or second stage or...? Or don't I need to do any of this because the stata ado takes care about it? (note that normalizing my instrument is not a problem).

Thank you very much!

Let $$X_1$$ be the $$(n \times k_1)$$ matrix for the endogenous variables and $$X_2$$ the exogenous $$(n \times k_2)$$ matrix for the additional exogenous variables.
Then the residuals from regressing $$X_1$$ on $$X_2$$ is given by: $$M_{X_2} X_1,$$ where $$M_{X_2} = (I - X_2(X_2'X_2)^{-1}X_2'))$$ Where $$I$$ is the identity matrix.
So you replace $$X_1$$ by $$M_{X_2}X_1$$ in the regression.
Alternatively, you can regress every variable in $$X_1$$ on all the variables in $$X_2$$ (i.e. running $$k_1$$ regressions). Then take the residuals of these regressions in the second stage.