IBM Support

Using a variable name as the second argument of a lead or lag function

Question & Answer


Question

I wish to compute new variables in SPSS Statistics with the LAG and LEAD functions. (LAG(X) uses the value of X from the previous case while Lead(X) uses the value of X from the following case.) I would like to specify a variable name (e.g. CUSTLAG), rather than an integer, as the span of cases to lag or lead, so that a different span size is used for each case. For the CREATE and SHIFT VALUES commands, if one wants to use a LAG() or LEAD() function, the second argument must be an integer. The same is true for the lag function in the COMPUTE command. How can I apply such a function in SPSS Statistics? Would a VECTOR and LOOP or DO REPEAT structure be required?

[{"Product":{"code":"SSLVMB","label":"IBM SPSS Statistics"},"Business Unit":{"code":"BU048","label":"IBM Software"},"Component":"--","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB76","label":"Data Platform"}}]

Log InLog in to view more of this document

This document has the abstract of a technical article that is available to authorized users once you have logged on. Please use Log in button above to access the full document. After log in, if you do not have the right authorization for this document, there will be instructions on what to do next.

Document Information

Modified date:
16 April 2020

UID

swg21645129