really complicated: how to cumulate one variable in function of the CHANGE in another

Hello everybody!

I got a SPSS file with the variables "user-id" "date" and than certain information about his consumer behaviour and payments for this particular month.

I now want to calculate -for example- the overall amount spent by every customer.
The user-ids are not consecutive.

So I need sth like

if "user-id" of case2 equals "user-id" of case1 then "new variable" (for case2)= "payment" of case1 + "payment" of case2

if "user-id" of case3 equals "user-id" of case2 then "new variable" (for case3)= "new variable" of case2 + "payment" of case3

and so on...

and then i need to get the last value if "user-id" of case(x) does not equal "user-id" of case(x+1)
best way to get this value is to have a second new variable with only the highest value for the same user-id!

I also want to calculate how long the customer stayed with the company and if he defected (last date does not equal a fixed "maximum date") or not (last date is this fixed "maximum date")

I hope u understand my problem and the dilemma i have solving it... in java i could imagine programming sth like that with some fors and ifs or whiles :)
but in SPSS!????

Thanks a lot for your help!


TS Contributor
Re: really complicated: how to cumulate one variable in function of the CHANGE in ano

This is rather a thread for the SPSS section of this forum. (Consider it moved - Dason)

After sorting for userid and date, you may perhaps use the LAG function

IF(userid ne LAG(userid)) sumvar= payment.
IF(userid = LAG(userid)) sumvar=lag(sumvar+payment).

To identify the highest value of sumvar you may use AGGREGATE.

Or you may simply use AGGREGATE from the beginning and ask for the sum of payments
wihtin each userid.

Kind regards