Stata xtset

The xtset command declares a panel dataset.


Usage

General use is:

. webuse nlswork
(National Longitudinal Survey of Young Women, 14-24 years old in 1968)

. xtset idcode year

Panel variable: idcode (unbalanced)
 Time variable: year, 68 to 88, but with gaps
         Delta: 1 unit

For datasets such as the demo datasets, the panel variable and time variable are preset so xtset can be called without any arguments.

Variable formats

Date and time formats do influence the output of panel commands. Consider:

. webuse patienttimes

. xtset pid tod

Panel variable: pid (unbalanced)
 Time variable: tod, 1.449e+12 to 1.449e+12, but with gaps
         Delta: 1 unit

. format tod %tc

. xtset pid tod

Panel variable: pid (unbalanced)
 Time variable: tod, 03dec2005 06:30:00 to 03dec2005 18:00:00, but with gaps
         Delta: .001 seconds

Equivalent to using the format command is using the format, i.e. xtset pid tod, format(%tc).

Balanced data

Balanced and unbalanced refers to whether each panel unit has a measurement for each time period. Compare the above unbalanced datasets to:

. webuse invest2

. xtset company time

Panel variable: company (strongly balanced)
 Time variable: time, 1 to 20
         Delta: 1 unit

A common issue is misspecifying the time units (e.g., specifying a wave for panel data that had cohorts added and subtracted across waves).

More generally, unbalanced panel datasets are common. This is not necessarily an issue, depending on the planned analysis.

For models where unbalanced data cannot be used, the 'issue' can be 'corrected' using tsfill to generate missing values for all gaps. The full option will furthermore generate missing values for the leading and trailing 'gaps', i.e. the time periods before and after the entity was actually being measured.

carryforward can be used to populate the gaps with the most recent non-missing value.

webuse nlswork
xtset idcode year
sort id
by id: carryforward birth_yr, generate(birth_yr2)
by id: carryforward birth_yr, replace

ipolate can be used to populate the gaps with interpolated values.


Operators

See tsset for the time series operators.


CategoryRicottone