SPSS Syntax 102: Recoding and Computing Variables, Calculating Descriptive Statistics

Once you’ve set up your SPSS data file, created variable and value labels to aid in interpretation of future analyses, and cleaned the data as necessary, it might be time to recode and compute new variables. You may also want to calculate some basic descriptive statistics regarding key variables in your data set. All of these tasks are remarkably simple using SPSS syntax. As a reminder, this forum focuses on common analyses performed by researchers and practitioners within organizational behavior, industrial/organizational psychology, and human resource management. An in-depth explanation of everything SPSS syntax can possibly do is far beyond this forum’s scope. The focus here is on practical issues and no-nonsense knowhow to bolster your productivity.

Recoding Variables

Although you may need to recode variables for a variety of reasons, the most common reason by far that I have to conduct this procedure is to deal with “reversed” items. That’s because I deal primarily with survey data about employee’s attitudes, such as job satisfaction, supervisory support, organizational commitment, and other related variables. Reversed items are those items for which the response options mean the exact opposite of the other items in a measure.

Here’s an example. The Survey of Perceived Organizational Support (Eisenberger, Huntington, Hutchison, & Sowa, 1986) originally had 36 items designed to assess employees’ global perceptions about how the degree to which the organization values their contributions and cares about their well-being. More recently, researchers (e.g., Roch & Shanock, 2006) used the six-item version of the original measure listed below with satisfactory results. Responses range from 1 (strongly disagree) to 5 (strongly agree).

1. My work organization is willing to help me when I need a special favor. 2. My work organization shows little concern for me. 3. My work organization takes pride in my accomplishments at work. 4. My work organization values my contributions to its well-being. 5. My work organization strongly considers my goals and values. 6. My work organization really cares about my well-being.

Notice how item number 2 differs from the other items. In responding to this item, an employee who perceived a very high level of organizational support would likely respond “disagree” to item number 2 but “agree” to the other five items. That’s because item number 2 is a reversed item. To properly analyze any measure that uses a reversed item, the analyst must recode that variable. Here’s the syntax to do just that (replacing “VARNAME” with the actual variable name):

recode VARNAME (1=5) (2=4) (3=3) (4=2) (5=1) INTO VARNAME_R. exe.

Running that syntax will create a new variable named “VARNAME_R,” which has been properly recoded. Now, we need to compute a new variable that takes the mean of each respondent’s responses to the items in each measure.

Computing New Variables

To continue the example above, we need to create one variable that represents respondents’ overall perceptions of organizational support, not just their responses to individual items. The process for doing this correctly may vary depending on what you’re measuring; for example, some psychometric scales require summing the responses while others take the items’ mean.

To calculate a composite variable for the measure described above, we take the mean. The syntax to do this is as follows (replacing “VARNAME” with the actual variable name):

compute VARNAMEOVERALL = mean (VARNAME1, VARNAME_R, VARNAME3, VARNAME4, VARNAME5, VARNAME6). exe.

Note that I used VARNAME_R instead of VARNAME2, because that’s the variable created during the recoding process. Running the compute command above will result in a new variable titled “VARNAMEOVERALL,” which is the mean average of the responses given to each of the measure’s six items. Also, the compute command works for all sorts of other transformations (not just taking the mean of other variables). So you can use it in many other instances as well.

Calculating Descriptive Statistics

Finally, you may want to know some basic information about your variables such as the frequency of responses to each of the response options and the items’ maximums, minimums, means, and standard deviations.

To do this, simply run the following syntax (replacing “VARNAME” with the actual variable name):

desc VARNAME1 VARNAME2 VARNAME3. freq VARNAME1 VARNAME2 VARNAME3.

Summary: The Running List of Syntax Discussed Thus Far

So here’s a running list of basic SPSS syntax that I’ve discussed on this forum thus far. Simply replace “VARNAME” with the variable name and make other adjustments as necessary for your specific situation.

Variable and Value Labels

variable labels VARNAME 'description of item or variable' . value labels VARNAME 1 'strongly disagree' 2 'disagree' 3 'neither agree nor disagree' 4 'agree' 5 'strongly agree'.

Compute New Variable

compute VARNAMEOVERALL = mean (VARNAME1, VARNAME_2, VARNAME3, VARNAME, VARNAME5, VARNAME6). exe.

Recode New Variable

recode VARNAME (1=5) (2=4) (3=3) (4=2) (5=1) INTO VARNAME_R. exe.

Descriptive Statistics and Frequencies

desc VARNAME1 VARNAME2 VARNAME3. freq VARNAME1 VARNAME2 VARNAME3.

To tell SPSS to run syntax commands, first copy and paste it into your syntax file. Then, simply highlight it and type CTRL+R on your keyboard. You can also select “run” from the menu at the top of the syntax file or click on the right-facing triangle in the menu bar.

References

Eisenberger, R., Huntington, R., Hutchison, S., & Sowa, D. (1986). Perceived organizational support. Journal of Applied Psychology, 71, 500-507.

Roch, S., & Shanock, L. (2006). Organizational justice in an exchange framework: Clarifying organizational justice distinctions. Journal of Management, 32, 299-322.