*! version 1.0 6 Sep 2020

Title

twset -- First step of the model based on Somaini and Wolak (2015).

Syntax

twset varlist
[weight]
[if]
[in]
[using]
[,
options]

[weight] Analytic weights can be added as an optional third argument

using followed by a path will save a set of matrices in that path. If using option is omitted, the matrices will be stored in eresults

generate(newvars) to create new group identifiers

varlist contains the name of the two group identifiers.

Description

twset is the first step of an algorithm to estimate the two-way fixed effect linear model. It uses the group identifiers and weights to create a set of matrices that can be used for multiple specifications.

Options

Full Description

using adding using followed by a path will save a set of matrices in that path. Otherwise, the matrices will be saved in eresults. STATA may fail if it tries to store a matrix that exceeds matsize in ereturn. Adding using avoids that limitation.

weight the optional third input can be a variable of analytic weights. If weight option is omitted then the weigth of every observation will be 1.

generate(newvars) if the group identifiers are not consecutive after dropping redundants and missing observations, then you have this option to create new group identifiers. This option will create new variables in the database.

Examples

twset hhid tid, gen(newids newts)

twset hhid tid

twset hhid tid w, gen(newids newts)

twset hhid tid w

twset hhid tid using "../folder/x", gen(newids newts)

twset hhid tid using "../folder/x"

Shortcomings

1. Use the if and in options to exclude observations with missing values in the variables included in the specification.

Common Errors

1. The algorithm will not work if the fixed effects after removing redundant and missing observations are not consecutives and the generate option is not used.

2. generate option: The algorithm wil break if the user tries to create a new variable with a name that already exists.

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 is 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 twset Github

Also see

twres
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.