------------------------------------------------------------------------------- help foronespell-------------------------------------------------------------------------------

Generate single longest spell for each unit in panel data, listwise

onespellvarlist[ifexp] [inrange] ,saving(name)[replace]

onespellis for use with panel data. You musttssetyour data before usingonespell; see helptsset.

Description

onespellproduces a subset of a panel data set in which all observations onvarlistare non-missing and contiguous in the time dimension. If a panel unit contains more than one such subset, the longest "spell" is retained.For instance, if a panel contains up to 20 years of data per firm, and firm

icontains non-missing values for all variables of interest for years 1-10 and 12-20, the first subset will be retained as that firm's single "spell" and years 12-20 will be discarded.If there are two or more spells of equal length, the latest spell will be retained. If firm

ihas non-missing values for all variables of interest for years 1-6, 8-13, 15-20, the spell for years 15-20 will be retained.Although performing this operation for a single variable of interest is fairly straightforward, this routine deals with a more challenging task: generating the single longest spell in a listwise fashion, across a set of variables. This applies the same logic as does, e.g.,

regress: an observation with a missing value in any variable will be deleted from the regression sample. Some matrix software (e.g., DPD for Ox) requires that panel data be organized in this fashion, with each unit appearing as a single contiguous block of non-missing observations.onespellwill produce such a dataset, which after conversion to Stata version 6 format (by, e.g., Stat/Transfer) may be read directly by Ox. The routine has been tested with the latest version of Ox (3.40) and the DPD package (1.21).

Options

saving(name)(a required option) causes the pruned dataset to be saved asname.dta. If that dataset already exists, thereplaceoption must be used.

Examples. webuse grunfeld, clear

. replace invest = . in 28 . replace mvalue = . in 55 . replace kstock = . in 87 . replace kstock = . in 94

. onespell invest mvalue kstock, saving(grun1)

AuthorChristopher F. Baum, Boston College, USA baum@bc.edu

AcknowledgementsMost of the computations in this routine are generated by N.J. Cox's

tsspellroutine. Thanks to David Roodman for assistance with the issues of moving data between hisxtabond2routine and DPD for Ox.

Also seeOn-line: tsspell