Archive for April, 2007

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:

COMPUTE NEW_VAR = VAR00001.
IF (VAR00002 = 4) NEW_VAR = 4 .
IF (VAR00002 = 5) NEW_VAR = 5 .
IF (VAR00002 = 6) NEW_VAR = 6 .
EXECUTE .

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


Calendar

April 2007
M T W T F S S
« Jan   Jun »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Posts by Month

Posts by Category