Path: janda.org/c10 > Overview of SPSS >
Computing a New Variable
Statistical Package for the Social Sciences

More on RECODE and COMPUTE Commands

Computing a New Variable

It's time to stretch your understanding of SPSS by elaborating on the RECODE and COMPUTE commands, which you can use to create your own variable from existing ones. Consider this example:

The citizen.sav data has are seven separate variables under the heading, Moral Values. For six of the seven, respondents were scored 1 if they said "yes" (e.g., believe in God) and 2 if they said "no." For the last question on Sexual Freedom, the scoring was somewhat different and reversed in direction. Those who consistently said "yes" to the first 6 questions and "disagree" to the seventh might be called "righteous" and those who consistently scored in the opposite direction might be termed "Unholy" -- with other response patterns in-between.

Suppose that you wanted to learn how citizens in each country responded to all seven questions, not just one. You can use SPSS to create your own variable (let's call it Unholy) by reversing the scoring for the Sexual Freedom variable and then summing the responses over all seven variables. Between the GET FILE command and the CROSSTABS command, insert a RECODE and a COMPUTE command as follows:

get file = '$CLASS/citizen.sav'.
recode freesex (1=3) (3=1).
compute Unholy= God + Aftrlife + devil+heaven+hell+freesex.
crosstabs Unholy by nation/cells=col.

These commands will produce the new variable Unholy. It will range from 6 (least Unholy) to 13 (most Unholy). Here is the CROSSTABS printout from that run.

Unholy  by  NATION  v01 NATION 
                                 NATION          
Col Pct  |United S Great Br West Ger France   East Ger 
         |tates    itain    many              many       Row 
         |     1  |     2  |     3  |     4  |     5  | Total
UNHOLY   +--------+--------+--------+--------+--------+-------
   6.00  |   4.8  |   2.2  |   3.3  |   2.2  |   1.2  |   159 
  LEAST  |        |        |        |        |        |   3.0 
         +--------+--------+--------+--------+--------+ 
   7.00  |  45.6  |  16.4  |  11.7  |  10.3  |   5.9  |  1115 
         |        |        |        |        |        |  20.8 
         +--------+--------+--------+--------+--------+      
   8.00  |  19.4  |  12.4  |   9.4  |   7.0  |   3.7  |   612   
         |        |        |        |        |        |  11.4 
         +--------+--------+--------+--------+--------+ 
   9.00  |  12.2  |  14.4  |  13.2  |   8.7  |   5.2  |   592
         |        |        |        |        |        |   11.1 
         +--------+--------+--------+--------+--------+       
  10.00  |   7.3  |  14.7  |  16.2  |  14.7  |   6.5  |   611 
         |        |        |        |        |        |  11.4     
         +--------+--------+--------+--------+--------+         
  11.00  |   6.5  |  14.3  |  18.6  |  24.4  |  18.1  |   806                 
         |        |        |        |        |        |  15.0 
         +--------+--------+--------+--------+--------+  
  12.00  |   2.6  |  15.1  |  13.3  |  17.6  |  18.8  |   657
         |        |        |        |        |        |  12.3 
         +--------+--------+--------+--------+--------+ 
  13.00  |   1.5  |  10.3  |  14.3  |  15.0  |  40.7  |   803  
   MOST  |        |        |        |        |        |  15.0 
         +--------+--------+--------+--------+--------+   
  Column    1500     1051     1088      712     1005     5355 
   Total    28.0     19.6     20.3     13.3     18.8    100.0
            

As you can see, Americans emerge as far more righteous by the consistency in their responses patterns to this battery of questions. You might use the RECODE (if necessary) and COMPUTE commands to create new variables for environmental attitudes, gender-related issues, political support, and so on.
Usually, researchers will rescore the variable to express the trait in a positive way, e.g., Holy rather than unholy.

Just make sure that you combine the variables in sensible ways.The computer has the capacity to transform dumb mistakes into huge fiascos. Just be thoughtful and careful in what you do.