Skip to Main Content

SPSS

Methods for Creating and Transforming Variables

Generating variables in SPSS is quite simple, especially if you want to generate a new variable from an already existing variable. Researchers often generate new variables that are copies of a current one if they want to change or recode the data, while also keeping the original data so it is not lost. There is no formula for generating a new variable as it is likened to “copy” and “paste”.

Below is the SYNTAX for generating the variable “age1” from an already existing variable “age”. 

SYNTAX

COMPUTE age1=age.

EXECUTE.

 

Our command is to COMPUTE the variable age1 that is equal to the variable age. When using the COMPUTE function in SPSS a second command EXECUTE is required. 

Below is the output for generating a new variable that is a copy of already existing data. 

Output

COMPUTE age=1.

 

It is simply the SYNTAX above, but without the “Execute” function. SPSS only gives us this output to tell us the SYNTAX ran correctly and there are no issues. Another way to check is to go “Dataset” page of SPSS and in “Variable View” our new variable, “age1” will be the last variable in the dataset.

We can also generate new variables that are transformed from other variables in the dataset. This is helpful if we want to collapse a variable from a higher level of measurement to a lower level of measurement, such as continuous to categorical.

Below is the SYNTAX for generating the new variable “education_new” from the variable “education” that is recoded from a continuous level to a categorical level.

SYNTAX

RECODE education (0 thru 12=0) (12.1 thru 20=1)  INTO education_new.

VARIABLE LABELS education_new 'recoded education from continuous to categorical variable'.

EXECUTE.

 

Our command is RECODE of the variable education where the values of 0 thru (through) 12 are recoded as a “0” and the values 12.1 thru (through) 20 are recoded to a “1”. We can also see another command VARIABLE LABELS, which is used to add a label of the variable so we can easily be reminded of how we created the variable education_new.

Output

The output for this is similar to the previous example above, where it is a copy of the SYNTAX. SPSS only gives us this output to tell us the SYNTAX ran correctly and there are no issues. Another way to check is to go “Dataset” page of SPSS and in “Variable View” our new variable, “education_new” will be the last variable in the dataset.

 

RECODE education (0 thru 12=0) (12.1 thru 20=1)  INTO education_new.

VARIABLE LABELS education_new 'recoded education from continuous to categorical variable'.

EXECUTE.

Standardizing a variable from raw values to standard values is often done for variables that do not have a normal distribution. In this case, we are standardizing the variable “age” in years to Z scores. 

Below is the SYNTAX that will create a new variable called "Zage" which will have the standardized Z scores of “age”. 

SYNTAX

DESCRIPTIVES  VARIABLES = age

 /SAVE.

 

Notice our command is DESCRIPTIVES of the VARIABLES age and the subcommand /SAVE converts the raw values to Z scores.  

Output

DESCRIPTIVES  VARIABLES = age

 /SAVE.

 

The output is a copy of the SYNTAX. SPSS only gives us this output to tell us the SYNTAX ran correctly and there are no issues. Another way to check is to go “Dataset” page of SPSS and in “Variable View” our new variable, “Zage” will be the last variable in the dataset.