help for panelthin

Identify observations for possible thinned panel dataset

panelthin
[if exp]
[in range]
,
generate(newvar)
minimum(#)

Description

panelthin identifies observations that would belong in a
thinned panel dataset in which observations in each panel are at least a
minimum time apart. The result is a new variable tagging observations
in the thinned dataset by 1 and others by 0.

Remarks

panelthin assumes tsset data and automatically
works separately on each panel in a panel dataset.

In essence, the first observation in each panel is selected,
then the next after at least a minimum time, and so on.

If a thinned dataset is acceptable, then (provided that the
main dataset is saved elsewhere) keep the set with
observations tagged 1 in the new variable.

The tags can be used to identify spells or runs in the data,
which most obviously may be helpful if collapse is to be used
in a reduction of the dataset. For more on the principles of identifying
spells, see Cox (2007).

Options

generate() specifies the name of a new variable to include
tags for selected observations. It is a required option.

minimum() specifies the minimum acceptable spacing in the
units of the time variable defining the panel. It is a required option.

Examples

clear

input id year whatever

4 1987 1

4 1988 3

4 1989 5

4 1990 7

4 1992 11

4 1993 13

4 1994 15

9 1987 42

9 1988 44

9 1989 46

9 1990 48

9 1992 52

9 1993 54

9 1994 56

end

tsset id year

panelthin, min(2) gen(tag)

list

keep if tag

list, sepby(id)

bysort id (year): gen spell = sum(tag)

collapse (min) year (mean) whatever, by(id spell)

list, sepby(id)

Author

Nicholas J. Cox, Durham University, UK

n.j.cox@durham.ac.uk

Acknowledgments

This problem was suggested by Rajesh Tharyan on Statalist.
http://www.stata.com/statalist/archive/2008-05/msg00772.html

Leny Matthew signalled a bug in an earlier version.

Andrea Stringhetti posted a problem at
https://www.statalist.org/forums/forum/general-stata-discussion/general/1555093-sorting-and-creation-of-variables
which led to emphasis on the scope for spell identification.

Reference

Cox, N.J. 2007.
Speaking Stata: Identifying spells.
Stata Journal 7: 249-265.
http://www.stata-journal.com/article.html?article=dm0029

Also see

On line: help for tsset