Differences between revisions 1 and 2
Revision 1 as of 2024-11-16 22:03:16
Size: 1361
Comment: Initial commit
Revision 2 as of 2025-04-04 01:02:46
Size: 1367
Comment: Standardize
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= TsSet = = Stata tsset =

Stata tsset

The tsset command 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)


CategoryRicottone

Stata/TsSet (last edited 2025-04-04 01:02:46 by DominicRicottone)