LAG Function (CREATE command)
LAG
creates
new series by copying the values of the existing series and moving
them forward the specified number of observations. This number is
called the lag order. The
table below shows a first-order lag for a hypothetical dataset.
- The specification on
LAG
is the name or names of the existing series and one or two lag orders, in parentheses. - At least one lag order must be specified; there is no default.
- Two lag orders indicate a range. For example, 2,6 indicates lag orders two through six. A new series is created for each lag order in the range.
- The number of new series specified must equal the number of existing series specified times the number of lag orders in the range.
- The first n cases at the beginning of the new series, where n is the lag order, are assigned the system-missing value.
- Missing values in the existing series are lagged and are assigned the system-missing value in the new series.
- A first-order lagged series can also be created using
COMPUTE
.COMPUTE
does not cause a data pass (seeCOMPUTE
).
X | Lag | Lead |
---|---|---|
198 | . | 220 |
220 | 198 | 305 |
305 | 220 | 470 |
470 | 305 | . |
Example
CREATE LAGVAR2 TO LAGVAR5 = LAG(VARA,2,5).
- Four new variables are created based on lags on VARA. LAGVAR2 is VARA lagged two steps, LAGVAR3 is VARA lagged three steps, LAGVAR4 is VARA lagged four steps, and LAGVAR5 is VARA lagged five steps.