*! version 1.0 6 Sep 2020

Title

twres -- performs the second step of the algorithm based on the model of Somaini and Wolak (2015).

Syntax

twres varlist
[using]
[,
options]

using followed by a path will use a set of matrices saved in that path. If using option is omitted the command will use the arrays stored in eresults

prefix(name) creates new variables that are the residual projection of the originals

replace replace the existing variables by their residual projection

Description

twres performs the second step of the algorithm. It is followed by a list of variables. These variables are projected onto the set of dummies and the residual of the projection is saved.

Options

Full Description

using adding using followed by a path will load a set of matrices saved in that path. Otherwise, the matrices will be loaded from eresults.

prefix(name) creates new variables, the residualized variables will be stored as new variables that will be named with a prefix specified in `newvars'. This option will create new variables in the database. See option replace for replacing existing variables.

replace replaces the variables for their residualized version. See option newvars for creating new variables without changing existent ones.

Shortcomings

1. If some of the variables has missing values the command will throw an error.

2. Factor-variable and time-series operators not allowed.

Common Errors

1. newvars option: trying to create a variable that already exists.

2. If using option is omitted: if the eresults were erased or overwritten by other command

Examples

twres y x1 x2, p(w_)

twres y x1 x2, replace

twres y x1 x2 using "../folder/x", p(w_)

Stored results

Scalars
e(dimN) number of first fixed effect without the redundants observations

e(dimT) number of second fixed effect without the redundants observations

e(rank_adj) Adjustment based on the rank of e(A) if e(dimN)<e(dimT), otherwise is based on the rank of e(C)

Macros
e(absorbed) name of the fixed effects absorbed and the weight variable

Matrices

If "using" is omitted

e(invDD) is a vector of (dimN)x1 taking the diagonal elements of the inverse of the matrix D'D

e(invHH) is a vector of (dimT-1)x1 taking the diagonal elements of the inverse of the matrix H'H

e(B) Matrix B is needed for the first and second step of the algorithm

If e(dimN)<e(dimT)

e(A) Matrix A is needed for the first and second step of the algorithm

e(CinvHHDH) Matrix CinvHHDH is needed for the first and second step of the algorithm

If e(dimN)>=e(dimT)

e(C) Matrix C needed for the first and second step of the algorithm

e(AinvDDDH) Matrix AinvDDDH is needed for the first step of the algorithm

Functions
e(sample) marks estimation sample

More information

For more information of twres Github

Also see

twset
twest
twsave
twload
twfem

References

Somaini, P. and F.A. Wolak, (2015), An Algorithm to Estimate the Two-Way Fixed Effects Model, Journal of Econometric Methods, 5, issue 1, p. 143-152.

Aditional References

Arellano, M. (1987), Computing Robust Standard Errors for Within-Groups Estimators, Oxford Bulletin of Economics and Statistics, 49, issue 4, p. 431–434.

Cameron, A. C., & Miller, D. L. (2015). A practitioner’s guide to cluster-robust inference. Journal of human resources, 50(2), 317-372.