Data Transformations: Conditional "IF" Statements
Overview: “If” statements are used to transform existing variables into new variables. For example, based on individuals’ scores on a Masculinity and a Femininity Scale, you might want to create a new variable that contains 4 categories (Masculine, Feminine, Androgynous, Undifferentiated). The four groups could be defined as follows: Masculine subjects score above the median on Masculinity and below the median on Femininity, Feminine subjects score above the median on Femininity and below the median on Masculinity, Androgynous subjects score above the median on both Masculinity and Femininity, Undifferentiated subjects score below the median on Masculinity and Femininity.
- To run: From the Data Editor Window
- Click “Transform”
- Click “Compute”
- The following Compute Variable dialog box will appear:
In the box labeled, “Target Variable” give a name to the new variable you want to create.
In the box labeled, “Numeric Expression” type 1 and Click “If...”
This will enable you to define your first group. The following Compute Variable: If Cases dialog box will appear:
Click “Include if case satisfies condition:”
In the box to the right, type a description of your first group. In the above example, the first group (Masculine) is made up of subjects with scores above the median=28 on Masculinity, and scores at or below the median=26 on Femininity.
Click “Continue”
Click on “OK”
You will be back to the Compute Variable dialog box.
Click on “OK”
A dialogue box asking whether you want to change the variable or not will appear.
Click on "OK"
REPEAT. You now have to repeat this entire procedure beginning with
Click on “Transform”
Click on “Compute”
In the numeric expression box the second time you type “2” and click on “If”
Type the description of your second group, Click on “Continue”, and when you return to the
Compute Variable dialog box, click “OK”.
REPEAT the entire procedure again for the remaining two groups.
After you have completed this procedure, you will see that the new variable you have just created appears at the end of your list of variables. You should now assign value labels for your new variable so that you will remember how you defined each group. Click on the new variable. Directions for how to assign value labels can be found under instructions for Defining Variables.