In SPSS, how do I generate a new variable?
To create a new variable in SPSS, use the
command. You can use this command in many ways:
- To create a variable called
totalequal to the sum of variables
v4, the syntax is:
compute total = v1+v2+v3+v4.
- You can use most basic mathematical expressions to combine
variables into new variables with
computestatements. Alternatively, you can also use SPSS functions with
computecommands. For example, the following command also adds the values of
v4to create a variable called
compute total = sum(v1 to v4).
Note: The difference between the two procedures above is that in the first procedure, the case on
totalwould be missing if any one of the four variables had missing values on a case; in the second procedure, the total would be computed while ignoring missing values on the four variables.
- You can use the
computecommand to create a copy of an existing variable that can be modified or recoded, while preserving the original values of the variable. For example, if you wish to create a copy of the variable
compute v1a = v1.
- You can also use the
computecommand to create a constant variable. For example, if you wish to create a constant variable called
v5and the value for the constant is 1, type:
compute v5 = 1.
For more on the
compute command, refer to the
Command Syntax Reference (PDF).
If you have questions about using statistical and mathematical software at Indiana University, email UITS Research Analytics. Research Analytics is located on the IU Bloomington campus at Woodburn Hall 200, and is open for consultation by appointment Monday-Friday 9am-5pm.
This is document afsh in the Knowledge Base.
Last modified on 2014-06-25.
- Fill out this form to submit your issue to the UITS Support Center.
- Please note that you must be affiliated with Indiana University to receive support.
- All fields are required.