Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 39 ยท Data Preparation

SPSS Recode and Visual Binning: Changing and Grouping Values

Use SPSS Transform > Recode into Different Variables, Automatic Recode and Visual Binning: old and new values, ranges, ELSE, missing codes, reverse scoring and RECODE syntax with examples.

Raw values are rarely in the form you need. Ages need to become age groups, a satisfaction item must be reverse-scored, text labels have to become codes, and the "don't know" answers must turn into missing values. In SPSS this is the job of Recode, Automatic Recode and Visual Binning, all found in the Transform menu. This lesson explains how each works and how to avoid the classic accident of overwriting your original data.

Same variable or different variable?

The Transform menu offers two Recode commands:

  • Recode into Same Variables overwrites the original values. There is no undo after you save. Use it only on a copy.
  • Recode into Different Variables creates a new variable and leaves the original untouched. This is almost always the right choice.

In syntax the two forms differ by the INTO keyword:

TEXT
RECODE satis (1=5) (2=4) (3=3) (4=2) (5=1) INTO satis_rev.
EXECUTE.

Without INTO, SPSS changes satis itself.

The dialog, step by step

  1. Transform > Recode into Different Variables...
  2. Move the input variable (say age) to the Input Variable -> Output Variable list.
  3. In Output Variable, type a Name (agegrp) and a Label ("Age group"), then click Change.
  4. Click Old and New Values...
  5. For each rule choose an Old Value and a New Value, then click Add.
  6. Continue, then OK (or Paste).

The Old Value choices are:

Old value Meaning
Value One exact value
System-missing Empty numeric cells
System- or user-missing Any missing value
Range Values between two numbers, inclusive
Range, LOWEST through value Everything up to and including a value
Range, value through HIGHEST Everything from a value upward
All other values Anything not matched so far

The New Value choices are Value, System-missing or Copy old value(s). You can also tick Output variables are strings or Convert numeric strings to numbers. The If... button on the main dialog limits the recode to cases that meet a condition.

Rules that matter

  1. First match wins. SPSS checks your rules in the order you listed them for each case and uses the first that matches. Ranges that overlap give the earlier rule precedence.
  2. Unmatched values become system-missing when you recode into a different variable, unless you add ELSE=COPY or ELSE with a value. Many beginners lose data here.
  3. When you recode into the same variable, unmatched values stay as they were.
  4. Ranges are inclusive at both ends. 18 THRU 34 and 35 THRU HI do not overlap; 18 THRU 35 and 35 THRU HI do.
  5. Decimals fall in the gaps between ranges: 18 THRU 34 and 35 THRU HI miss 34.5. Use LO THRU 34.999 or let ELSE catch it.

An age grouping with a missing-code rule:

TEXT
RECODE age (999=SYSMIS) (LO THRU 17=1) (18 THRU 34=2) (35 THRU 54=3) (55 THRU HI=4)
  INTO agegrp.
VARIABLE LABELS agegrp 'Age group'.
VALUE LABELS agegrp 1 'Under 18' 2 '18-34' 3 '35-54' 4 '55 and over'.
EXECUTE.

Always add value labels to the new variable, and check it with Frequencies and a crosstab of old against new.

Python Stand-in: a RECODE engine with first-match-wins

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

In the output, 34.5 becomes None (system-missing) because it falls between 18 THRU 34 and 35 THRU 54. In SPSS you would see a period. Fix by using 18 THRU 34.999 or by making the second rule ELSE.

Reverse scoring

Questionnaires often mix positive and negative items ("I enjoy..." and "I dread..."). Before adding items into a scale, reverse the negative ones so a high score always means the same thing. For a 1 to 5 item, the new value is 6 minus the old value. You can do it with a recode (1=5, 2=4, 3=3, 4=2, 5=1) or with a computation: COMPUTE item3_r = 6 - item3. See compute variable and functions.

Python Stand-in: reverse scoring and checking it

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Automatic Recode

Transform > Automatic Recode... turns values (often text) into consecutive integers (1, 2, 3, ...) in alphabetical order. It is handy when a string variable such as city has to become numeric, because the original text is kept as the value label. Options:

  • New Name and Add New Name for each input variable.
  • Recode Starting from: Lowest value / Highest value.
  • Use the same recoding scheme for all variables.
  • Treat blank string values as user-missing.

The syntax is AUTORECODE VARIABLES=city /INTO city_n /PRINT. The /PRINT option lists the mapping in the output. Because the codes follow the alphabet (and sorting is case-sensitive in some locales), the order is arbitrary: re-set the labels if you need a custom order such as Low, Medium, High.

Python Stand-in: automatic recode of text into labelled codes

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Visual Binning

Transform > Visual Binning... groups a scale variable into categories using its histogram. It is better than hand-written ranges because you see where the cutpoints fall.

  1. Pick the variable to bin and click Continue.
  2. Give a Binned Variable name and label.
  3. Click Make Cutpoints... and choose:
    • Equal Width Intervals: first cutpoint, number of cutpoints or width;
    • Equal Percentiles Based on Scanned Cases: each group has about the same number of cases (quartiles with 3 cutpoints);
    • Cutpoints at Mean and Selected Standard Deviations.
  4. Click Apply, then Make Labels to generate labels like "<= 17" and "18 - 34".
  5. OK creates the new variable.

The result is an ordinal variable. Binning loses information: only bin when you need categories for a crosstab or chart, and keep the original variable for correlations and regression.

Python Stand-in: equal-width and equal-percentile cutpoints

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The skewed income values show the trade-off: equal-width bins can leave most cases in one group, while percentile bins even out the group sizes but have uneven widths. (SPSS's own percentile definition differs slightly from Python's; see frequencies and percentiles.)

Other value-changing tools

  • Transform > Rank Cases... replaces values by their rank, with options for ties and for Rankit and normal scores.
  • Transform > Count Values within Cases... counts how often chosen values occur across variables of a case.
  • Transform > Replace Missing Values... fills gaps in numeric series.
  • Data > Define Variable Properties... relabels and sets missing codes without recoding.

Common mistakes

  • Using Recode into Same Variables on the only copy of the data.
  • Forgetting that unmatched values become system-missing in a different variable.
  • Overlapping or gapped ranges, especially with decimals.
  • Reverse scoring twice, or forgetting to reverse some items.
  • Not adding value labels to the new variable, then misreading the output.
  • Binning a variable you later need as a continuous predictor.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You recode age into a different variable with rules (18 THRU 34=1) and (35 THRU 54=2). What happens to a case aged 60?

    Values that match no rule become system-missing in the new variable unless ELSE=COPY or an ELSE value is given.
  2. 2. Which is the safer menu choice for creating an age group?

    Different variables keeps the original values intact.
  3. 3. What does Automatic Recode keep as value labels?

    The original strings become value labels of the new numeric codes.
  4. 4. Which Visual Binning cutpoint method puts roughly equal numbers of cases in each group?

    Percentile-based cutpoints are chosen so each bin holds about the same number of cases.

Summary

  • Recode into different variables unless you truly mean to overwrite; the first matching rule wins.
  • Unmatched values become system-missing in a different variable; use ELSE or COPY to keep them.
  • Reverse-score negatively worded items before combining them.
  • Automatic Recode converts text to labelled codes; Visual Binning builds groups from a histogram.
  • Add value labels and verify the result with Frequencies or a crosstab.

Next: Compute Variable, Functions and Conditions