Hi all,
I am applying the Frisch-Waugh-Theorem to partial out a set of fixed effects D and get the OLS estimates and standard errors of the remaining regressors X.
The idea is mainly to use the code to pre-process data, but I would like to understand exactly how to get correct OLS results before doing anything.
Below a MWE in Mata to clarify what I do.
For reference I report also a benchmark when using -areg-.
I hope I haven't made trivial mistakes, in fact it seems that all estimates (including the separately computed constant) correspond to the ones reported by -areg-. However, I am not sure how to get the standard error of the constant without inverting the full (X, D)'(X, D) variance-covariance matrix (which would make very little sense, given the setting).
Thanks for any comments.
The question is cross-posted at https://stats.stackexchange.com/ques...-waugh-theorem
I am applying the Frisch-Waugh-Theorem to partial out a set of fixed effects D and get the OLS estimates and standard errors of the remaining regressors X.
The idea is mainly to use the code to pre-process data, but I would like to understand exactly how to get correct OLS results before doing anything.
Below a MWE in Mata to clarify what I do.
For reference I report also a benchmark when using -areg-.
Code:
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
Thanks for any comments.
The question is cross-posted at https://stats.stackexchange.com/ques...-waugh-theorem
Comment