Language Reference

DIF Function

DIF (x <, lags> <, delRows> ) ;

This function is supported by the IML procedure and the iml action.

The DIF function computes the differences between data values and one or more lagged (shifted) values for time series data. The arguments are as follows:

x

specifies a n times 1 numerical matrix of time series data.

lags

specifies integer lags. The lags argument can be an integer matrix with d elements. If so, the DIF function returns an n times d matrix where the ith column represents the difference between the time series and the lagged data for the ith lag. If the lags argument is not specified, a value of 1 is used.

delRows

is an binary flag variable that specifies whether to delete certain rows in the result matrix. By default, delRows is 0 and the output matrix contains the same number of rows as the input vector. If delRows is nonzero, then the first max(lags,0) rows and the last min(lags,0) rows of the result matrix are deleted. For example, if x has n elements and y=DIF(x,3), then y is an n-element vector whose first three rows contain missing values. In contrast, z=DIF(x,3,1) returns a vector that has n minus 3 elements and that equals y[4:n].

The values of the lags argument are usually positive integers. A positive lag shifts the time series data backwards in time. A lag of 0 represents the original time series. A negative value for the lags argument shifts the time series data forward in time; this is sometimes called a lead effect. The DIF function is related to the LAG function.

For example, the following statements compute the difference between the time series and the lagged data:

x = {1,3,4,7,9};
dif = dif(x, {0 1 3});
print dif;

Figure 123: Differences between Data and Lagged Data

dif
0..
02.
01.
036
026


Last updated: April 11, 2025