# SPSS Statistics

View Only

## Compute Variable IF...

• #### 1.  Compute Variable IF...

Posted Tue June 08, 2021 02:57 PM

I have two ordinal variables VAR1 and VAR2 with response options: 1 = 0-10%, 2 = 11-25%, 3 = 26-50%, 4 = more than 50%. What is the numeric equation to compute L2SES

IF (VAR1 <= 2 AND VAR2 >= 3) L2SES = 1 "more affluent"

IF (VAR1 >=3 AND VAR2 <=2) L2SES = 3 "more disadvantaged"

IF (all other combinations of VAR1 and VAR2) L2SES = 2 "neither affluent nor disadvantaged"

#SPSSStatistics
#Support
#SupportMigration

• #### 2.  RE: Compute Variable IF... Best Answer

Posted Tue June 08, 2021 04:01 PM

You could pretty much just use what you wrote, but a slightly more readable way would be

DO IF VAR1 <= 2 AND VAR2 >= 3.

COMPUTE L2SES = 1.

ELSE IF VAR1 >=3 AND VAR2 <=2.

COMPUTE L2SES = 3.

ELSE.

COMPUTE L2SES = 2.

If you have any missing values, however, in the input variables, you should test for that first as none of the branches written this way will be executed.

#SPSSStatistics
#Support
#SupportMigration

• #### 3.  RE: Compute Variable IF...

Posted Thu February 22, 2024 03:37 PM

I have tried to use the "compute if" function in SPSS to create a new variable from two other variables with multiple categories but to no avail even after following format here. I keep getting the error message: "Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command".

The following are my command lines:

DO IF V1051 = 2 AND V102 = 1.
COMPUTE MITY = 0.
ELSE IF V1051 = 2 AND V102 = 2.
COMPUTE MITY = 1.
ELSE IF V1051 = 1 AND V102 = 1.
COMPUTE MITY = 2.
ELSE IF V1051 = 1 AND V102 = 2.
COMPUTE MITY = 3.
ELSE IF V1051 = 0 AND V102 = 1.
COMPUTE MITY = 4.
ELSE.
COMPUTE MITY = 5.

------------------------------
Ebenezer Nikoi
------------------------------

• #### 4.  RE: Compute Variable IF... Best Answer

Posted Tue June 08, 2021 05:37 PM