Posts filed under '2. Enhancing your data'

Combine two variables into one

One of the many questions we got the last few days was from Dana. Dana asked us a question about combining two variables into one:

“Hello, I need to essentially combine two variables that have been
standardized into one new variable.  Data that is present in one variable
is missing on the other and vice versa.  I tried making a new variable and
then recoding missing data so it would pull in the values from the other
variable.  Can you only recode missing values into numbers, or can I pull
an entirely different variable into it?  Basically, how do I combine two
variables into one?  Is there an easier way? Thanks!”

Well, there certainly is an easier way to combine two variables. Let’s assume you have the variables VAR00001 and VAR00002 which you want to combine into one new variable. We also assume that they do not have overlapping records, with which I mean that there is no record which has a value in both variables. To combine the two, you can use the following SPSS Syntax:

IF (VAR00002 = 4) NEW_VAR = 4 .
IF (VAR00002 = 5) NEW_VAR = 5 .
IF (VAR00002 = 6) NEW_VAR = 6 .

The first part (COMPUTE NEW_VAR = VAR00001.) creates the new variable and copies all values from  VAR00001 into the new variable. The second part copies the values from VAR00002 to the new variable, for the values 4, 5 and 6. Very probably, your second variable contains different values, so adjust the Syntax to your needs.

19 comments April 10th, 2007 andris

Does SPSS remember the formula used in Compute?

This week Eamonn send us the following question about the Compute function:

When using transfor/compute – say to create a construct from a set of Likert
Scale items – does SPSS save the formula used to create the new variable, or
is it lost once you compute?

SPSS does not save the formula in your data file. It does keep the formula in mind if you keep SPSS open. So if you want to use the same formula again, but than with different variables for example, you can open the Compute screen again, and there your old formula is. But if you close SPSS and open it again, the formula will be gone.

6 comments January 19th, 2007 andris

Create an overall variable / rating from a number of ratings / variables

This week Cameron send us the following question:

“I am writing about the stereotypes that people hold in regard to public service employees. Participants are required to rate a private, state, federal and local employee on a number of ratings such as efficiency. It is a 7 point Likert scale.

How do I obtain an overall rating score for each participant for each level of employee?”

Cameron, I assume you have already got your data into SPSS. I also assume you have put each score in a different variable and scored every variable with a figure from 1 to 7. To create an overall rating, you can use the Compute function. You can find this under Transform -> Compute.

(Click image for large view)

  • In the field Target Variable, you fill in the name of a (new) variable which should contain the overall rating.
  • In the field Numeric Expression you create a formula by typing or clicking the right buttons, like the following:


  • In this formula the 4 stands for the number of variables.
  • When you are finished, press OK.

In the newly created variable you can now find the overall score. If you have any questions about SPSS, please do not hesitate to contact us.

1 comment September 29th, 2006 andris

Question: How to store each subset after splitting a file

Question: Hi all!

After a SPLIT command applied to my file, I would like each generated subset
of data to be saved in a different .sav file.

Is there an easy way to do that using SAVE or XSAVE?

Even if SPSS can manage each subset separately, I did not find how to save
each subset separately.
Do not hesitate if I am not clear enough or if you need more information.

My data is organized as follows:
Source Destination other variable
david Stefan 123
Nico Bruce 213
Nico Stefan 333
Stefan Nico 2
david Stefan 5
Stefan Nico 56

I want to split my file according to each unique combination
, hence, I use:

SPLIT FILE SEPARATE BY Source Destination.
Hence I have my data sorted as I need:
Source Destination other variable
david Stefan 123
david Stefan 5
Nico Bruce 213
Nico Stefan 333
Stefan Nico 2
Stefan Nico 56

Now, what I need, is to have all the records for each distinct pairto a different file.
Assuming that my first file is called file.sav, I would like to have:
file_david_Stefan.sav with all records with
file_Nico_Bruce.sav with all records with
file_Nico_Stefan.sav with all records with
and so on…
Thanks you for your help.

Answer: Here is the better way.DO IF source=?david? and destination=’Stefan’.
XSAVE OUTFILE=?file_david_Stefan.sav?.
ELSE IF source=?Nico? and destination=’Bruce’.
XSAVE OUTFILE=?file_Nico_Bruce.sav?.

Do you also need an answer on your spss question, submit your question here.

2 comments March 26th, 2006


September 2011
« Apr    

Posts by Month

Posts by Category