Lag function
The Lag function creates a new regular time series in which the data values lag the source time series by a fixed offset.
Syntax
Lag(ts TimeSeries,
nelems integer)
returns TimeSeries;
- ts
- The source time series.
- nelems
- The number of elements to lag the series by. Positive values lag the result behind the argument, and negative values lead the result ahead.
Description
Lag shifts only offsets, not the source time series. Therefore, a lag of -2 eliminates the first two elements. For example, if there is a daily time series, Monday to Friday, and a one-day lag (an argument of -1) is imposed, then there is no first Monday, the first Tuesday is Monday, and the next Monday is Friday. It would be more typical of a daily time series to lag a full week.
For example, this function allows the user to create a hypothetical time series, with closing stock prices for each day moved two days ahead on the calendar.
Lag is valid only for regular time series.
Returns
A new time series with the same calendar and origin as the source time series but that has its elements assigned to different offsets.
Example
select Lag(stock_data,3)
from daily_stocks
where stock_name = 'IBM';