Recode into new variable with same values

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

statsgirl
Posts: 16
Joined: Sat Aug 04, 2012 1:52 am

Recode into new variable with same values

Postby statsgirl » Mon Oct 15, 2012 8:06 pm

In my dataset, I am recoding several variables into new ones with the exact same values as before. I thought a simple "Recode var1 into var2" would do this but then I get this error message: "On the RECODE command, the list of variables to be recoded includes the name of a nonexistent variable." Of course I can write it this way: "Recode var1 (1=1) (2=2) (3=3) into var2." However, there are many many values for each variable, and this would take a little while. Is there a simpler, more elegant way to create this syntax?
apeape
Posts: 56
Joined: Mon May 02, 2011 6:07 pm

Re: Recode into new variable with same values

Postby apeape » Mon Oct 15, 2012 9:46 pm

The argument to copy existing values using the recode command is "else=copy" so you would need to write:

Code: Select all

recode oldvar (else=copy) into newvar.
But given that you're not interested in recoding but want to duplicate the variable exactly the easiest way is to just use compute:

Code: Select all

compute newvar = oldvar.
statsgirl
Posts: 16
Joined: Sat Aug 04, 2012 1:52 am

Re: Recode into new variable with same values

Postby statsgirl » Mon Oct 15, 2012 9:50 pm

Thank you!

Who is online

Users browsing this forum: No registered users and 1 guest

cron