1. Home
  2. Create Lagged Values/Differences from a Column

Create Lagged Values/Differences from a Column

Use this to menu to create a column of lagged values (from a variate or factor) or to create lagged differences within a variate. A lagged value is a value from a previous or following unit in the column and is equivalent to using the SHIFT function. A lagged difference is the difference between the current observation and a previous or following value and is equivalent to using the DIFFERENCE function. The lags can be applied just within specified groups with the Groups to lag within list. The results depend on the order of the rows within the spreadsheet. You can specify a different order by entering factors or variates into the Sorted order of units within groups list. The rows are then taken in the order defined by their sorted values. Note, the ordering of the rows in the spreadsheet is unchanged after the calculations.

Column to lag

This selects the column (variate or factor) in the spreadsheet whose values are to be used for the lagged values or differences.

Calculate differences (variates only)

If this is selected, the differences between the previous or following values will be calculated. The difference is Y$[i] – Y$[i – lag] for previous values and Y$[i] – Y$[i + lag] for following values.

Lagged column

This gives a new name for the resulting column of lagged values or differences.

Lag

This is a positive integer (L) that defines the size of the lag.

Lag direction

This defines the direction of the lag.

Previous values The lagged value for the current row is taken from L rows before it
Following values The lagged value for the current row is taken from L rows after it

Initial/Final values

This is the value to place in positions for which there are no values L units before (or after when Following values is selected). By default, this has a missing value (*). For example, a value of 0 could be used if the original series started from zero.

Available factors

This lists the factor columns in the spreadsheet. Double-click a name to copy it to the Groups to lag within list. You can transfer multiple selections from Available data by holding the Ctrl key on your keyboard while selecting items, then click to move them all across in one action.

Groups to lag within

This forms the lags or differences within specific groups. For example, if you had repeated measures on subjects, you would not want to take the past of future values from another subject. Double-click a name to remove it from the list. You can remove multiple selections from the list by holding the Ctrl key on your keyboard while selecting items, then click to remove them all in one action.

Available data

This lists the columns in the spreadsheet. Double-click a name to copy it to the Sorted order of units within groups list. You can transfer multiple selections from Available data by holding the Ctrl key on your keyboard while selecting items, then click to move them all across in one action.

Sorted order of units within groups

This defines the order of observations within each group. If the rows are not in to the order in which you want to take the lags, you can specify factors or variates here to define how the rows should be sorted to give the required lags. If this is not set, the current row order is used. For example, if you had repeated measures on subjects, you would want the rows to be sorted in time order, so the previous observation would be the last time before the current one. Double-click a name to remove if from the list. You can remove multiple selections from the list by holding the Ctrl key on your keyboard while selecting items, then click to remove them all in one action.

Example

Column Y is lagged by one previous value to give PY, and by one following value to give FY. Columns PG and FG are formed by lagging Y within groups defined by G. Column D is formed by differencing Y at lag one from the previous value.

  G     Y     PY     FY     PG     FG     D  
  1   1   *   4   *   4   *
  1   4   1   9   1   9   3
  1   9   4 16   4   *   5
  2 16   9 25   * 25   7
  2 25 16 36 16 36   9
  2 36 25 49 25   * 11
  3 49 36 64   * 64 13
  3 64 49 81 49 81 81
  3 81 64   * 64   * 17

Action buttons

OK Calculate the lagged column close the dialog.
Apply Calculate the lagged column and leave it open to do another calculation.
Cancel Close the dialog without creating any columns.
Clear Clears the lists and column name.
Help Open this help page.

See also

Updated on April 17, 2024

Was this article helpful?