Data Manipulation

SPSS® Reference Manual: A guide for market researchers

Prepared by Paul Hartzer

Contents

The SPSS status bar

At the bottom of the SPSS data window, there is a series of rectangles. From left to right, these tell you:

Weighting: Turning on

GUI method

  1. Click on the scale button.*
  2. Select "Weight cases by."
  3. Select the variable you want to weight on.
  4. Click on the right arrow.
  5. Click OK.

Syntax method

WEIGHT BY VAR1.

Weighting: Turning off

GUI method

  1. Click on the scale button.*
  2. Select "Do not weight cases."
  3. Click OK.

Syntax method

WEIGHT OFF.

Weighting: Changing

GUI method

  1. Turn off the previous weight.
  2. Turn on the new weight.

Syntax method

Weighting by a new variable will automatically turn off the previous weight.

WEIGHT BY VAR1.

* Note: If the Scale button is not present, click Data on the menu and choose Weight cases....

Filtering

GUI method

  1. Click on the yellow highlighted grid button.*
  2. Click on "If condition is satisfied" and then If....
  3. Build your filter in the box at the upper right. This can be done by selecting variables and the buttons below, or by typing directly in the box (or some combination of both). Here are some examples:
    1. If you want all men over the age of 40, the filter might be GENDER = 1 AND AGE > 40
    2. If you want everyone who either makes between $50,000 and $100,000 or who lives in Detroit, the filter might be (INCOME >= 50000 AND INCOME <= 100000) OR CITY = 14 (where 14 is the city code for Detroit).
    3. If you want to find everyone who gave a response to the race question, the filter might be NOT MISSING(RACE)
  4. For the most part, the functions the casual user will implement in filters are
    1. AND, OR, NOT
    2. =, <, >, <=, >=, <> (or ~=)
    3. MISSING(). MISSING() is used to find out if a particular record has data for a particular variable.
  5. If you need to know what values a variable has, right click on the name in the variable list and pick Variable Information.
  6. Decide if you want to filter or delete unwanted records:
    1. Filtering: If you're just filtering for an analysis, select Filtered under Unselected Cases Are.
    2. Deleting: If you want to delete records from the data file, select Deleted instead. Only do this if you want to permanently alter the data file.
  7. Once you've created the filter you want, click OK.
  8. To turn off a filter, repeat step 1, and then pick All Cases and click OK.

Syntax method

Filtering for analysis (keep the unselected records in the datafile):

COMPUTE filter_$=().
FILTER BY filter_$.

For instance, example 3a would be:

COMPUTE filter_$=(GENDER = 1 AND AGE > 40).
FILTER BY filter_$.

Note that filter_$ can be any valid variable name. What this does is create a new variable that is 1 if the record satisfies the case and 0 if it doesn't. Deleting records with a filter (delete the unselected records from the datafile):

SELECT IF ().

For instance, example 3a would be:

SELECT IF (GENDER = 1 AND AGE > 40).

Note that filter_$ can be any valid variable name.

Turning the filter off:

USE ALL.

* Note: If the Grid button is not present, click Data on the menu and choose Select cases....

Recoding

Recoding has two main purposes:

When recoding, using the syntax method is usually less difficult than using the GUI method. However, both are included here.

GUI method

  1. On the menu, select Transform.
  2. If you want to recode existing variables, pick Recode > Into Same Variables.... Otherwise, pick Recode > Into Different Variables....
  3. Chose the variables to recode and click the right arrow. Whatever recodes you specify will be done to all variables.
  4. If you're creating new variables, enter their names and labels in the Output Variable box and click Change.
  5. To create a recoding condition, click Old and New Values. A new dialog box will open (see next page).
  6. In the new dialog box, specify a value or, if you want to recode a range (say, 0 to 30), click Range and enter the range.
  7. For the new value, enter a value.
  8. Click Add.
  9. Continue 6-8 for all recodes. If you want to just copy all the rest of the values without changing them, click All Other Values and Copy Old Value(s). Make sure to add each condition.
  10. When you're done, click Continue.
  11. If you want to specify a condition for your recode (for instance, you want to make the respondent gender = 1 if the head of household = 1), you can create that condition by clicking on If.... See Filtering above for information on how to build filters.
  12. Click OK.

Syntax method

To recode Var1, Var2, and Var3 into new variables:

RECODE Var1 To Var3 (oldval=newval)(ELSE=COPY) INTO Vara1 To Vara3.

If the variables after the INTO portion don't exist, SPSS will create them. To use the same variables, leave off the INTO portion:

RECODE Var1 To Var3 (oldval=newval)(ELSE=COPY).

To blank out a value, recode into SYSMIS:

RECODE Var1 To Var3 (oldval=SYSMIS)(ELSE=COPY).

To recode a range:

RECODE Var1 To Var3 (oldval1 thru oldval5=newval)(ELSE=COPY).

For instance, say you have an age variable that you want to convert into an age group variable. These are the rules:

This would be the syntax:

RECODE AGE (16 thru 34=1)(35 thru 54=2)(55 thru 99=3)(ELSE=SYSMIS) INTO AGEGROUP.

As a second example, say you've learned that two of the values were reversed at the third panel company. 2 should have been "Black" and 3 should have been "Asian," but it was the other way around at that panel company only. The recode syntax would be:

RECODE RACE (2=3)(3=2)(ELSE=COPY).

However, to limit it to just the panel company in question, use the DO IF... structure:

DO IF (PANEL=3).
RECODE RACE (2=3)(3=2)(ELSE=COPY).
END IF.

Return to Contents - Back to File Handling - Continue to Data Analysis