Giacomo Rosaspina
Giacomo Rosaspina

Reputation: 111

How to compute a variable from an existing variable in SPSS

I would create a variable in SPSS and add it in the existing dataset. Particularly this variable should be: x-y if x>y and 0 if x<=y (x and y are variables in the dataset). How can I do?

I'm interested to learn this both writing the syntax of the script as using the guided tool "compute variable".

thanks in advance

Upvotes: 1

Views: 181

Answers (2)

eli-k
eli-k

Reputation: 11310

Here's another one liner:

compute z = (x-y)*(x>y).

Upvotes: 0

JKP
JKP

Reputation: 5417

There are many ways to do this. The simplest is compute z = max(x-y, 0).

Upvotes: 1

Related Questions