Using SPSS to Transform Variables
This tutorial will show you how to use SPSS version 10 to automatically recode variables, manually recode variables, and compute variables. You can either read or watch this tutorial.
This tutorial assumes that you have:
Automatic Recode
Sometimes a variable needs to be changed before it can be used by SPSS. There are two common techniques used to accomplish this goal -- recode and compute.
Recode is used to change the values of one variable into other values. It is commonly used to change a string variable into a numeric, nominal equivalent. For example, you may want to recode the MAJOR variable from its string values (e.g. Math, English) into a numeric variable (e.g. math becomes 1, English becomes 2, etc.) This is useful with many of the inferential tests, such as the ANOVA procedures.
There are two ways of recoding a variable. The easiest way is to let SPSS automatically
do it for you. SPSS will sort the string values from highest to lowest (or vice versa) and
then assign consecutive numbers to the values. It also adds the string value as a label
to the numeric value. To use the automatic recoding select Transform | Automatic Recode:
The automatic recode dialog box appears:
Select the variable that you want to recode from the list at the left by clicking on it
and move it into the Variable->Name Name box on the right by clicking on the arrow button.
In this example, we will automatically recode the Major If Not Psychology variable:
Click on the box to the right of the New Name button (the button is dimmed, so it may
be hard to read, but it is immediately below the Variable -> New Name box). Type in the
new SPSS variable name. Remember that the SPSS variable name must be no more than 8
characters long, consist only of numbers and letters, and must start with a letter. Then
click on the New Name button. In this example, we will call the new variable MAJORNUM. (Don't
forget to click on the New Name button after typing the variable name):
Click on OK to perform the recoding. The SPSS output viewer will appear with the
summary of the automatic recoding:
The output shows the old value of the variable and its corresponding new value and label. For example, the value "ART" in the MAJOR variable has been recoded to 1 in the new MAJORNUM variable. The value 1 in the MAJORNUM variable has been assigned the label "ART".
Manual Recode
The second way of recoding a variable is more flexible, but more time consuming.
Select Transform | Recode | Into Different Variables to perform the more flexible
recoding method:
The Recode into Different Variables dialog box appears:
Select the variable that you want to recode from the list at the left by clicking on
it. Move it into the Input Variable -> Output Variable box by clicking on the arrow
button. In this example, we will transform the Major If Not Psychology variable (again):
Click in the Name box in the Output Variable section. Type in the name of the new
SPSS variable that will hold the recoded values. Remember that variables names cannot
exceed 8 characters in length, must consist of numbers and letters, and must start with
a letter. Then click on the Change button. In this example, I will call the new variable
MAJORNM2:
Now click on the Old and New Values button to tell SPSS how each old value should be
recoded into a new value. The Recode into Different Variables: Old and New Values dialog
box will appear:
For each value of the old (MAJOR) variable, you will enter the corresponding value of the
new variable. Click in the text box to the right of Value in the Old Value frame of the
dialog box. Type in a value of the old variable. Be careful -- the old value must
exactly match or that part of the recode will not occur. In this example, we will
recode "MATH" (one of the four values of MAJOR) into the value 1. Enter MATH (in all
capital letters) into the Old Value Value text box:
Click in the Value text box in the New Value frame. Type the new value that corresponds
to the old value that you just typed in the Old Value frame. In this example, the old
value of MATH corresponds to the new value of 1:
Click on the Add button next to the Old -> New text box:
Repeat the process for the remaining old and new values. In this example, we have
three additional values to recode:
Old | New |
ENGLISH | 2 |
ART | 3 |
HISTORY | 4 |
This is what the Recode into Different Variables: Old and New Values dialog box should
look like when you are done:
Click on the Continue button to return to the Recode into Different Variables dialog box. Click on OK to perform the recode.
We still do not have labels attached to the values of the new variable. Scroll in the
SPSS Data Editor window until the new variable is visible. Double click on the gray
column heading of the variable:
This causes the Variable View to appear:
Double click in the rectangle at the intersection of the row with the desired variable
(majornm2 in this example) and the column with the heading "Label." Type a label that
describes the variable. In this example, the label might be "Major If Not Psychology":
Click in the rectangle at the intersection of the row with the desired variable
(majornm2 in this example) and the column with the heading "Values." A small button with
an ellipsis in it will appear in the rectangle:
Click on the button with the ellipsis. The Value Labels dialog box will appear:
Click in the text box to the right of Value in the Value Labels dialog box. Type in one
of the values of the variable. We will start with value 1:
Click in the Value Label text box and enter the label for this value of the variable.
In this example, Math was the label associated with value 1, so type Math:
Click on the add button to add the label:
Repeat the process for the three remaining variables:
Value | Value Label |
2 | English |
3 | Art |
4 | History |
This is what the Define Labels dialog box should look like when you are done:
Click on the OK Button in the Value Labels dialog box. Click on the Data View tab
at the bottom of the screen to return to the data:
Computing Variables
Computing is similar to recoding except that computing allows you to specify a mathematical or logical expression that is used to recode the data. This feature is often used to transform the data in order to meet an assumption of a statistical test. It can also be used to collapse several variables that measure the same concept into a single variable, thus increasing the reliability of the measure.
In this particular example we will collapse the responses to questions 10 through 14
which all attempt to measure extraversion into a single variable called EXTRA1. The five
questions are summarized below:
Question | Value for High Extraversion |
---|---|
I would rather stay at home and read than go out with my friends. | HIGH |
One of my favorite pastimes is talking to people. | LOW |
I live a fast paced life. | LOW |
I hardly ever sit around doing nothing. | LOW |
I am an extravert. | LOW |
For each of the questions, identify whether a high value or a low value represents a person who has a large amount of extraversion. For example, a person who strongly disagreed with the first question, "I would rather stay at home and read than go out with my friends" would probably be more extraverted than a person who strongly agreed with that statement. Since strongly disagree corresponds to a value of 5 on the scale, a high response to this question corresponds to a more extraverted individual.
Before we can collapse the five questions into a single value, we need to write the
formula:
EXTRA1 = FRIENDS + (6 - TALK) + (6 - PACE) + (6 - SIT) + (6 - EXTRAVER)
Each of the variables that have a low value for high levels of extraversion have
been inverted in the formula (by computing 6 - variable.) This makes the scales
of all the questions consistent as shown in the following table:
Value | 6 - Value |
---|---|
1 | 5 |
2 | 4 |
3 | 3 |
4 | 2 |
5 | 1 |
To perform the computation, select Transform | Compute:
The Compute Variable dialog box appears:
Click in the text box below Target Variable and type the name of the new variable that
will hold the computed value. In this example, the new variable will be called EXTRA1:
From the list at the left, select the first variable of the equation by clicking on it.
Move that variable into Numeric Expression box by clicking on the arrow button. In this
example, click on the Friends variable and move it by clicking on the arrow button:
Enter the rest of the equation. Click the + button (or press the + key on the keyboard).
Click on the parentheses button () (or press the left parenthesis key on the keyboard).
Click on 6, and -. Move the Talk variable into the Numeric Expression text box. Continue
until you have entered the entired expression into the Numeric Expression text box. It
should look like this when you are done:
Click on the OK button to perform the computation. If you scroll all the way to the right in the SPSS Data Editor you will see the new variable and its values.