Saturday, July 14, 2012

Stata Time Series Operators (Lags, Leads, and Indices)

For reference because I always end up having to look this up:

lag: L, L2, … : gen lag2Var = L2.var

lead: F, F2, … : gen lead2Var = F2.var

difference: D, D2, … : gen diffofdiffVar = D2.var

seasonal difference: S, S2, … : gen seadiffVar = S2.var

I have never used the seasonal difference. I assume it depends on the seasonal frequency defined via tsset.

D2 is defined as (y[t]-y[t-1]) - (y[t-1]-y[t-2]), and not y[t]-y[t-2]. For y[t]-y[t-2], if there are no gaps in the time variable, you can use y[_n]-y[_n-2].

Reference: Forecasting in STATA: Tools and Tricks [Economic Forecasting (Econ 390) Spring 2010]