How to Recode String Variables in SPSS

In this quick tutorial, we’re going to look at how to recode a string variable as a numeric variable in the SPSS statistics program.

This is often done using the automatic recode functionality of SPSS, but in this case we’re going to do it manually because of the extra control we get.

Quick Steps

  1. Click on Transform -> Recode into Different Variables
  2. Drag and drop the variable you wish to recode over into the Input Variable -> Output Variable box
  3. Create a new name for your output variable in the Output Variable (Name) text box, and click the Change button
  4. Click the Old and New Values… button
  5. Type the first value of your input variable into the Old Value (Value) text box, and the value you want to replace it with into the New Value (Value) text box. Then click Add to confirm the recoding
  6. Repeat this process for all the existing values of your input variable
  7. Press Continue, and then OK to do the recoding
  8. The new recoded output variable will appear in the Data View

 

The Data

We’re assuming that you’ve fired up SPSS, opened a data file, or entered new data, and you’re looking at the Data View window.

SPSS data view recode string

The issue we have with our data is that the Education variable has been coded as a string whereas it should be numeric. SPSS provides a number of options to help us to recode the variable. We’re going to look at the Recode into Different Variables method.

Recode into Different Variables

As its name suggests, if you choose this option, SPSS will use an input variable to create a new recoded variable.

To begin this process, click on Transform -> Recode into Different Variables, which will bring up its associated dialog box.

SPSS recode into different variables

You need to drag and drop the variable you want to recode over into the Input Variable -> Output Variable box (it reads String Variable -> Output Variable, above, because SPSS has identified the Education variable as a string).

The next step is to give your new recoded output variable a name, and then to hit the Change button. As you can see, we’ve called our new recoded variable EdNumeric.

Once you’ve got this set up, click the Old and New Values… button so you can specify how you want to recode the variable.

Old and New Values

The Old and New Values dialog box allows you to specify new values for your existing input variable.

SPSS old and new values dialog

This is easy to accomplish. The old value goes into the Old Value (Value) text box on the left, and the new value you want to replace it with into the New Value (Value) text box on the right. Then click Add to confirm the recoding.

Repeat for all the existing values of your input variable.

As you can see above, we’ve got “School” recoded as 1, and we’re about to add “Graduate” recoded as 2.

Once you’ve got the recoding set up, press Continue.

That’s it, really. Press OK to recode your variable.

The Result

If you take a look at the Data View, you’ll see you’ve got a new variable which contains the recoded values.

SPSS data view with recoded variable

Our new EdNumeric variable is a numeric, nominal variable, where 1 = School, 2 = Graduate and 3 = Postgrad.

You could just leave it at that, but probably you’d want to set up Value Labels. This is the topic of a separate tutorial, so we won’t explain how to do that here, but the advantage of doing so is that you’ll end up with meaningful labels in your output, and you don’t have to remember how the coding works.

Recoded values SPSS with value labels

Once you’ve set up Value Labels for the new EdNumeric variable, there will be no difference between its appearance and that of the old Education variable. The only thing that has changed is the underlying coding, which is now numeric.

***************

That’s it for this quick tutorial. You should now be able to recode string values into a different variable in SPSS. In future tutorials, we’ll look at some of the other options for recoding values in SPSS.