Differences between revisions 3 and 4
Revision 3 as of 2025-10-24 18:34:47
Size: 1357
Comment: Rewrite
Revision 4 as of 2025-12-18 16:00:59
Size: 1461
Comment: Link
Deletions are marked like this. Additions are marked like this.
Line 72: Line 72:
----



== See also ==

[[https://www.stata.com/manuals/tstsset.pdf|Stata manual for -tsset-]]

Stata tsset

-tsset- declares a time series dataset.


Usage

. webuse gdp2
(Federal Reserve Economic Data, St. Louis Fed)

. tsset daten

Time variable: daten, 01jan1952 to 01oct2010, but with gaps
        Delta: 1 day

. tsset tq

Time variable: tq, 1952q1 to 2010q4
        Delta: 1 month

Stata will indicate if there are gaps in observations. A common issue is misspecifying the time units (e.g., specifying a date for time series data that was collected weekly)


Operators

Time series variable operators:

  • L.foo = lagged reference

  • LN.foo = reference lagged by N time periods

  • F.foo = forward reference

  • FN.foo = reference forwarded by N time periods

  • D.foo = difference between L.foo and foo

  • DN.foo = difference between LN.foo and foo

  • S.foo = seasonal difference between L.foo and foo

  • SN.foo = seasonal difference between LN.foo and foo

Note also that the operators are case-insensitive.

As an example:

webuse gdp2
tsset tq

// Create new variables
generate l_gdp_ln = l.gdp_ln
generate l_l_gdp_ln = l2.gdp_ln

// Directly reference
regress gdp_ln l.gdp_ln


Analysis

twoway (line gdp_ln tq)


See also

Stata manual for -tsset-


CategoryRicottone

Stata/TsSet (last edited 2025-12-18 16:00:59 by DominicRicottone)