SPSS
COMMANDS
PART 1
compute
Use compute to create a new variable or calculate values for a previously defined variable. The general form of this command is as follows:
compute
<variable name> = <instructions>.
The command is comprised of the command word compute, a variable name for a variable that’s already been defined
or an entirely new variable name, an equals sign, and instructions telling SPSS what you want computed.
The instructions can be comprised of many types of expressions, including
adding, subtracting, multiplying, and dividing, among others. The operations
can be performed on variables and/or numbers. Here are some examples:
compute
once = 1.
compute onevar = another.
compute whole = part1 + part2 + part3.
compute model = 0.342 * (educ + age) /10.
Compute is executed for every case (observation). SPSS assigns the variable in your compute expression to take on the value of the expression on the right side of the “=“ sign. If the variable is not already one of the variables in the SPSS data file you have opened, SPSS will add it to the variables in memory (it is not at this time added to the data file on the desktop). If the variable to the left of the “=“ sign already exists, SPSS will discard the old value and replace it with the new value calculated by the compute command.
NOTE: if any variable on the right side of the “=“ sign, contains a
missing value for a given observation, then the value of the variable in the
compute command will be assigned to missing. For example, in the command,
compute yearborn = syear - age.
the variable yearborn is set to
missing if syear or age has a missing value.
crosstabs
The
crosstabs command is used to construct a “cross-classification” table. This is a breakdown of the frequencies of one
variable for each category of another.
The simple format of this command is:
crosstabs
tables = dependent by independent.
This command will produce a
table with the number of rows equal to the number of valid categories of the
dependent variable and the number of columns equal to the number of valid
categories of the independent variable.
The “/cells” option can be added to the crosstabs command to instruct
SPSS to include a breakdown of percentages in the table. The “I” preceding the option informs SPSS that what comes next is an
option on the crosstabs command.
For example:
crosstabs
tables = dependent by independent /cells = count column.
will produce
a crosstab including frequencies and column percentages. NOTE:
As long as the dependent variable is the row variable, you will wish to
look at column percentages. By default,
crosstabs displays cell counts if there is no “cells” option specified.
Another
option that we will use with crosstabs is the “/statistics” option. In this class we will look at three
statistics:
1) Chi Square – the measure of statistical
significance for bivariate relationships.
2)
Lambda
– a measure of strength for bivariate relationships with categorical
(i.e., nominal) variables.
3) Gamma – a measure of strength for
bivariate relationships with ordinal variables.
frequencies
The frequencies command counts the number of times each value occurs for a variable. The command takes the form of the word “frequencies” followed by “variables = “ to tell SPSS that what comes next is a list of the variables for which you want frequencies. Finally, you type a list of variables.
For example,
frequencies
variables = age sex race sibs.
will tell SPSS to generate frequency tables for the variables “age”,
“sex”, “race”, and “sibs”. In addition to the basic frequencies command,
options can be added to tell SPSS to output other information, such as “barchart”
to create a bar chart of the frequency distribution, or “statistics” to tell
SPSS to output standard statistics on the variable. A frequencies command with
these options might look like this:
frequencies
variables = relig /barchart.
The “I” preceding the option
informs SPSS that what comes next is an option on the frequencies command.
missing values
By using the missing values command,
you can tell SPSS what values of a variable represent missing information. The
command:
missing
values bday (97, 98, 99).
instructs SPSS that the codes 97, 98, and 99 are considered to represent
missing information for the variable bday.
NOTE: SPSS will only recode three values of a variable to be missing values.
If you have a variable which has more than three values which need to be
declared missing, you will need to use the recode command to recode one value
of the variable you want to declare missing in with another value you want to
declare missing.
recode
The recode command is used to change the value of a variable. You may want to do this to put the data into a form that you need for a particular analysis. For example, if you want to analyse two income groups, but the variable you have for income is in the form of exact dollars, you would use recode to put tht data into groups. For example:
recode
rincom91 (0 thru 15000 = 0) (else = 1).
will change the values of the variable “rincom9 1" to equal 0 if the original value of the variable is between 0 and 15000, and it will be reassigned to equal 1 if the original vale was greater than 15000.
Another example of using recode might
be to invert the order of the values for a subjective evaluation variable. For
instance, the variable “happy” has three valid response categories:
1 = Very Happy
2= Pretty Happy
3 = Not Too Happy
You might want to change the order to go from least happy to most happy. To
do this, all you need to do is swap the values 1 and 3. The recode statement that will accomplish
this is:
recode happy (1=3) (3=1).
After swapping these values, the original 3’s will be 1’s, and the
original l’s will be 3’s, or:
1 = Not Too Happy
2 = Pretty Happy
3 = Very Happy
It is important to keep in mind that when you change the way the variable
is coded, the value labels are NOT changed. This can be fixed by using the value labels command:
recode happy (1=3) (3=1).
value labels happy 1 ‘Not Too
Happy’ 2 ‘Pretty Happy’ 3 ‘Very Happy’ 9 ‘NA’.
See the value labels entry below for more details on the value labels command.
select if
(<arguments>)
The select if command tells
SPSS to select only those cases for which the argument is true. For example, to
select only those individuals (of “respondents”) who reported that they were
either “Black” or “White” in terms of their race (i.e., to exclude those who
answered with the only other option, “Other”-- check the variable using the
frequencies command), the following select
i[command, or “statement, is used:
select if (race = 1 or race = 2)
In this example, the argument is: (race=1 or race = 2). Only those individuals who have a value of 1 or 2 for the variable race will be included in the SPSS analyses after this statement is executed. This will result in excluding all individuals who are not either ‘Black” or “White”—everyone in the remaining category, “Other”, will be excluded from subsequent analysis.
value labels
Use the value labels command to
assign labels to each attribute or category of a variable. The value labels command identifies what
each value of the variable represents. For example,
for the variable sex,
value labels sex 1 ‘Male’ 2 ‘Female’.
assigns the label “Male” for a code of 1 on the variable sex, and “Female” for a code of 2.
variable labels
A variable label is used to expand on the meaning of a particular variable. Although we make an attempt to be as descriptive as possible in the name of the variable, the variable name is limjted to eight characters, and seldom is sufficient to be very descriptive. Use the variable labels command to clarify or elucidate the content of your variables. SPSS can usually print up to 40 characters of a variable label. It is not necessary to use a variable label, though it is often useful to keep things straight and understandable. The syntax for the variable labels command is:
variable
labels <variable name> ‘Description of variable’.
If you want to give labels to several variables, you can list them all
under the same variable labels command.
For example:
variable labels god ‘R believes in a
supreme being’
dog ‘R acts on instructions from a dog’
psycho ‘R killed interviewer when questioned’.