Shift and smooth: previous value, next value, change, moving average
In brief
The data assistant "Shift and smooth" (Edit data) creates new columns from a number column: the value of the previous or next measurement (previous value, next value, delay k), the change from the previous measurement (also in percent) and the moving average. This corresponds to the functions LAG, LEAD, DIFF, MA and PMA of the SPSS command CREATE. The calculation is per person in long format (one row per measurement), the time column sets the order; the rows of the data stay as they are. The value of another person never enters.
Trap: gaps in time
SPSS knows only the order of the cases. If a measurement is missing, the "previous value" is the measurement before, not the one a time unit before. Example person B with the times 1, 2, 4, 5 and the values 5, 6, 8, 9: previous value by order ., 5, 6, 8; only at distance 1 instead ., 5, ., 8. Statable calculates by order (default) and then shows, clearly visible above the result, for how many people time points are missing. The choice "only if the distance is exactly k time units" otherwise leaves the cell empty. The same holds for the change.
Moving average
- Centered (SPSS MA): odd span s: mean of the s values around the measurement. Even span: mean of two non-centered means, the edge values count half (like the Time series card and the decomposition in R). At the edge and for any window with a missing value the cell stays empty.
- Trailing: two choices. "The last values including the current value" (default, R smooths this way with filter(sides = 1)) and "the values before, without the current value (SPSS PMA)". They give different numbers; both labels say whether the current value is included.
More rules
- Two measurements of the same person at the same time are blocked, with the number of rows. SPSS carries on silently here.
- Change in percent: 100·(value − value before)/|value before|. If the value before is 0, the cell stays empty (with a sentence).
- A missing value moves along: if a measurement follows a missing value, its previous value is empty. A row without person or time stays empty and does not disturb the others.
- The case weight is not used in the new columns.
Sources
IBM SPSS Statistics Knowledge Center, version 23: CREATE (functions LAG, LEAD, DIFF, MA, PMA).