April 10th, 2007 andris
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:
COMPUTE NEW_VAR = VAR00001.
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.