help xtbalance2 v. 1.0 - 29. January 2021

Title

xtbalance2 - Create a balanced subsample from unbalanced panel data.

Syntax

xtbalance2 [varlist] [if] [in] ,
generate(newvarname)
[optimisation(string)
]

Data has to be xtset before using xtbalance2; see xtset.
varlist may contain time-series operators, see tsvarlist.
If varlist is empty, xtbalance2 uses all variables in the dataset.

Contents

Description

Options

Saved Values

Examples

About

Description

xtbalance2 creates a balanced subsample from an unbalanced dataset.
xtbalance2 does not drop any observations, it creates a variable indicating if
an observations (or row) is part of the balanced subsample.

xtbalance2 tries to maximise either the number of cross-sectional units (ids),
time periods or total number of observations.
To do so it uses a simple algorithm which finds the largest subsquare in a matrix.
Theoretically it is possible to obtain more than one solution to the maximisation problem.
In this case xtbalance2 creates an indicator variable for each solution.

Options

generate(newvarname) Name of the indicator variable.

optimisation(T|N|NT) which dimension to be optimised/maximised. Default is length of the time series (T).
N maximises the number of cross-section units and NT uses the maximum number of observations
from N and T.

Saved Values

Scalars
r(NumMax) Number of possible solutions for maximum number of N|T|NT. If larger than 1, potential problems can arise.

Examples

use http://www.stata-journal.com/software/sj12-1/st0246/manu_prod, clear.

To maximise the observations with respect to the number of cross-sectional units (N_g):

xtbalance2 , generate(balanceN) optimisation(N)

xtbalance2 creates a new variable called balanceN which takes the value 1
if the observations is included in the new balanced panel and 0 otherwise.

We can do the same but maximise the observations with respect to the number of
time periods:

xtbalance2 , generate(balanceT) optimisation(T)

To restrict optimisation to a specific set of variables:

xtbalance2 lO lL lY, generate(balanceT2) optimisation(T)

Author

Jan Ditzen (Free University of Bozen-Bolzano)

Email: jan.ditzen@unibz.it

Web: www.jan.ditzen.net

xtbalance2 was created for the use in xtcse2.
All remaining errors are my own.

Please cite as follows:

Ditzen, J. 2021. xtbalance2: Create a balanced subsample from unbalanced panel data.

The latest versions can be obtained via net from https://github.com/JanDitzen/xtbalance2
.

Changelog

This version: 1.0 - 29 January 2021

Also see

See also: xtset