I am applying in Frisch-Waugh Theorem to partial out a set of fixed effects
D and get the OLS estimates and standard errors of the remaining regressors
The theorem is more general, but one leading application is to re-center the outcome and the right-hand side variables about group means ("de-meaning"), hence absorbing the group fixed-effects without having to estimate them (see for instance the discussion here).
Below a MWE in Stata/Mata to clarify what I do. If you have a solution with another software, it is well accepted, I am mainly interested in the theory behind it.
y is price,
D is turn, and
X corresponds to the remining right-hand side variables (including other fixed effects,
trunk) and the constant.
For reference I report also a benchmark when using
cls clear all sysuse auto, clear // Benchmark areg price gear length i.trunk, absorb(turn) // Absorb "manually" in MATA xi i.turn i.trunk gen uno = 1 mata // import y = st_data(., "price") X = st_data(., ("gear", "length", "_Itrunk_*", "uno")) D = st_data(., "_Iturn*") // demeaned X and y M_D = I(rows(y)) - D * qrinv(cross(D,D)) * D' // "residual maker" M_D = I - D(D'D)^(-1)D' y_dem = M_D * y X_dem = M_D * X // OLS using de-meaned variables and corresponding standard errors b1 = qrsolve(X_dem, y_dem) res2 = cross(y_dem - X_dem*b1, y_dem - X_dem*b1) MSE = res2/(rows(X_dem) - (cols(X_dem)+cols(D)-1)) XX_dem = qrinv(cross(X_dem, X_dem)) SE = sqrt(diagonal(XX_dem) * MSE) SE // Compute constant as c = y_bar - X_bar*b1 e = rows(b1) - 1 c = mean(y) - (mean(X[., 1..e]) * b1[1..e])' c end
All the coefficients (including the separately computed constant) correspond to the ones reported by
-areg-. Also the standard errors are correct, except for the one relative to the constant, which I am not sure how to get.
Any help is highly appreciated.