SPSS offers two choices under the recode command: *I**nto Same Variable* and *Into **Different Variables. *

The command *I**nto Same Variable* replaces existing data with new values, but the command *Into **Different Variables* adds a new variable to the data set.

In almost every situation, you want to use *Into Different Variables*. Recoding *Into Same Variables* replaces the values in the existing variable.

So if you notice a mistake after you’ve recoded, you can’t fix it.

But you may not even notice the mistake, because you can’t even test it.

**And that’s just dangerous.**

So do not recode over an existing variable unless you are absolutely certain that the lost information will never be needed.

Here is an example of how to do it in the menus. This is from the General Social Survey data set that comes along with SPSS. In it, I am recoding Educ, Years of Education, into 5 categories: Less than High School, High School Grad, Some College, Bachelor’s degree, More than college.

*Transform*

*Recode Into Different Variables*

This dialog window will come up:

I filled in the following:

*Numeric variable:* Educ

*Output variable Name:* Educ_Cat

*Output variable Label: *Education in Categories

Click *Change*

Click *Old and New Values*

This Dialogue Window will pop up:

Fill in the following:

*Old Value: Range: Lowest Through:* 11

*New Value: Value:* 1

Click *Add*

*Old Value: Value 12*

* New Value: Value:* 2

Click *Add*

*Old Value: Range: *13* Through:* 15

*New Value: Value:* 3

Click *Add*

*Old Value: Value: 16 *

*New Value: Value:* 4

Click *Add*

*Old Value: Range: *17* Through Highest*

*New Value: Value:* 5

Click *Add*

* Old Value: System- or User-Missing*

* New Value: System Missing*

* *Click *Continue*

* *Click* OK*

Or, you could do all of that in just a few lines of very logical syntax code:

RECODE educ (12=2) (16=4) (MISSING=SYSMIS) (Lowest thru 11=1) (13 thru 15=3) (17 thru Highest=5) INTO Educ_cat.

VARIABLE LABELS Educ_cat ‘Education in Categories’.

EXECUTE.

If you don’t have many variables to recode, say one or two, it’s not a big deal to use the menus (but at least **paste the code**, so you have a record of what you did later!).

But if you have more than just one or two, all those mouse-clicks get old, fast.

And if you need to go back and change your coding scheme, say to combine two small categories, it’s a quick matter to update the code. In the menus you have to start over.

(And of course, once you recode, you should immediately **enter value labels** and test your syntax to make sure it worked. Both are easy to do with **syntax**).

Want to learn more? If you’re just getting started with data analysis in SPSS, or would like a thorough refresher, please join us in our online workshop **Introduction to Data Analysis in SPSS**.

**Missing Data**,

**Mixed Models**,

**Structural Equation Modeling**,

**Data Mining**,

**Effect Size Statistics**, and much more..

{ 75 comments… read them below or add one }

Hello, I have a model : qualitative IV (with three odor conditions) and DV: quantitative and moderator variable metric (likert scale with several items from 1 to 7 degrees). my questions are:

– When the MV is metric, do I have to recode the categorical variable before Testet moderation?

– How to recode moderator variable (Likert scale) in class (high level vs. low) in spss when it is a single item or more?

– In the general linear model variable moderating factor is it random?

– When the interaction effect was significant between VM and IV on the DV, how do you know that one of the two terms of the MV that best explains the DV?

I block a lot on this point and I need your help please. Thank you in advance.

I need mostly spss procedures for testing moderation and transofrmation moderating variables.

Hi Karim,

I’m going to answer your questions one at a time.

1. No, and usually you don’t want to. You’re just throwing away information.

2. You would do it using Transform–>Recode into Differerent Variable. But don’t do it anyway.

3. No. If the moderating variable (MV) is a factor (i.e. categorical), just enter it into fixed factors. If it’s continuous, add it to Covariates. Then go to the Model tab to create an interaction between the IV and the MV. This will occur by default if both are factors, but not if one is continuous.

4. By terms, I assume you mean the items you’re combining to create the MV. You don’t. By combining them, you’re making the assertion that the combination is the moderator, not the individual items. If you need to see the effect of each individual item, you need to put them in separately.

And I would suggest taking a look at our webinars and workshop–we’ve got a lot of free ones, and there are quite a few on this topic. I think you’d find it helpful.

Karen

I would like to create interval ratio variable from class+degree but how do i describe the new variable?

Hi Dorla,

I’m only guessing that class and degree are categorical variables. You can’t get interval or ratio data for each person that is a combination of categorical variables, unless you mean something like “the number of people in each class with a certain degree.”

So I’d need more info.

Karen

hello, how to know whether data that i have is already recoded or not?

Hi Farah,

There is no way to tell for sure without a codebook. But if you see strange patterns (ie. one variable has a strong negative correlation whereas all others are strong positive), that’s a good sign. But that will only be a sign if the results are very clear.

Best,

Karen

I have a few questions and I’m not 100% sure this is where I should be asking them.. I have a bunch of data that is in code form that I want to track on spss. There is about 10,000 different codes. I want to add the codes to spss as value lables and I also need to recode the existing data into 1,2,3,4,etc. What is the best way of doing this and is it possiable???

Hi Nadine,

Both recoding and assigning value labels are possible.

If you a lot of variables, you definitely want to use syntax to do both.

The commands are RECODE and VALUE LABELS. If you look them up in the Command Syntax Reference manual. It’s in the Help as a pdf.

Karen

oh well!!!thanks !!!

Hi:

I am a very nervous (:) doctoral student who is trying to finish his data analysis using SPSS 20.0. I am having problems mergin two variables that should have been together (days/weeks). I learned how to transform the variables, but I am not sure if I can merge the two of them days an weeks. Days=1, and weeks=2. Right now I have two separate columns: Days 0=No, 1=Yes, and Weeks 0=No, 1=yes.

Thanks,

Ivan

Hi Ivan,

I’m not sure what you’re trying to end up with. But it sounds like there are four possibilities:

1. Days=Yes, Weeks=Yes

2. Days=Yes, Weeks=No

3. Days=No, Weeks=Yes

4. Days=No, Weeks=No

Do you want one variable with those four categories? Or somehow combine those four combinations into two?

Karen

Dear Karen,

I am interested in similar question. Namely, in my SPSS database I have 7 categorical variables (YES=1, NO=0), and I would like to create only two variables, where first three from those 7 should be in the FIRST NEW VARIABLE and four others sholud be in the SECOND NEW VARIABLE. Namely, i have 7 ways to reward employees, and first three are related to the so call profit sharing and other four are related to the bonuses, so I would like to create only two variables – instead of 7… Is this possible? Thank You in advance!

Nemanja

Hi Nemanja,

Sure. But how you do it depends what you want the new variables to measure. Should the first new variable be a count of the yeses across the first three variables? Or a Yes if any of the original three variables were yes?

This is the first thing to figure out.

Hi Karen,

I am brand new to SPSS trying to recode variables. Just needed to when im recoding multiple sets of variables does it change the values of other variables? I hope that makes sense

HI Sitha,

As long as you choose “Recode into Different Variables” you are actually creating a new variable, so it should not change the values of any existing variables.

Karen

If you made a mistake and didn’t spot it until later, it also helps to have saved the Data Editor with a different name: that way you can always go back to the previous version.

There’s an example on my website of RECODE with reversed Likert scales from a survey of teenage attitudes, followed by analysis and some comments on the results (see:

http://surveyresearch.weebly.com/23-data-transformations.html

and especially

http://surveyresearch.weebly.com/-35-derived-variables-count-and-compute.html

Hi!

1) I have a dependent variable (Degree of empowerment -DoE)measured in 10 different dimensions using a 6-point likert scale. I would like to combine the 10 dimensions into a single measure of degree of empowerment (DoE). what approach I can use in spss?

2)The independent vatiables: some are dichotomous (Yes/No) and others are also ordinal. I want to explore how they influence degree of empowerment (DoE) what analyses can I perform?

Thanks,

Orest

Hi Orest,

The first sounds like either a Principal Component Analysis or an Exploratory Factor Analysis.

The second sounds like a multiple regression (linear model). That’s where I would start, at least. If you’d like a consultation to go over it, let me know.

Hello,

I am new to spss and currently doing a secondary analysis using an existing data sets. I have two variables

1.Partners drinks Alcohol? Yes/NO

2.Frequency of getting drunk Never/Often/Sometimes

I am trying to merge the NO category of variable 1 to 2 in order to obtain a 3rd variable

3 Alcohol measure….NO/Never/Often/Sometimes.

I will appreciate any help on how to go about this on spss 19.

Thank you.

Hi Maureen, you need to use recode (in the transform menu) and it’s going to require a few If conditions.

For example: if Partners=No Alcohol=No

if Partner=Yes and Frequency=Never Alcohol=Never

etc.

There are a lot more steps along the same line–it would be hard to explain here (we do this in a workshop and it takes a while to show all the steps).

Is there a way to transform a variable on one scale (a Likert from 1-7) to a different scale (1-9) without z-scoring?

Not that I know of. I think Z scores are your best bet.

I have a very large data set (17 million records) where responses were free form and contains spelling errors and multiple ways to characterize the same compound. For example, Activated Charcoal comes up as ACTIVATED CHAR, activated charcaol, ACT. CHAR, etc. How would these be recoded into the same grouping? Would I be able to use “*.*”?

That’s a tricky one, and I suspect it will be slow no matter what you do, but I would look into the substring function.

New to SPSS, could you provide a little more detail/reference on substring function? Is this done through a macro command or from the drop down menu in SPSS?

Hi,

I am trying to do analysis of my research data, but getting stuck! I really need help on how to do correlation analysis. How do i combine for instance 7 factors into one variable? I need to run a bi-variate corerlation but the several factors are disturbing me. Thanks.

Hi John, It sounds like you need to do a correlation matrix, which is a table of bivariate correlations between each pair of variables. You’ll have a LOT of correlations in that table.

hello ,i have few questions want to ask about the spss

first,when i use the “transform” ->”record into different variable” to make a new range

ex.1~10 become 1

10~20 become 2

20~30 become 3

when the data have the num 10 then it will come out at the “1”,why?

second ,is

ex.100~200

201~300

301~400

when the data have the num 200.23 or other ，they will come out missing value，why？

thank you

It depends on exactly how you’re writing the syntax. Try using 10.0001, for example, on your second grouping. That should take care of it.

hi,

my question is how can I do in recoding “often true, and sometime true” to “Yes” for coding as 1. I want to combine the “often and sometimes” as “Yes” and “never and don’t know” as “No”. Then Yes=1 and No=1. Thank you for your time.

Hi, Using principal component analysis of factor analysis I can load 4 items to 1 component. There I need to consider this loaded factor(component) as an independent variable in the further analysis. So how do I create variable for result factor of factor analysis.

Hi Praneeth,

You stat software should have an option to save your factor scores as a new variable. Once you’ve saved this variable to the data set, you can use it in other analyses. If you are using SPSS, there is a save button within the factor analysis procedure.

I have a research about diabetes, and I want to test hypothesis that is female mean equal to male mean or not, I tried to do it in SPSS but always there is no result

Warnings

The GROUPS subcommand specifies an unknown variable or a long string variable. This subcommand must specify either a numeric variable or a short string variable. Text found: gender

Execution of this command stops.

can some one help me please?

Hi Amar,

I assume you’re using the oneway ANOVA procedure. I was surprised by this one as well, many years ago.

Despite the fact that the grouping variable should be categorical, it wants a numeric variable.

My suggestion? Use GLM instead. Put that grouping variable into Fixed Factors. Does the same analysis, but without the hassle.

Hi Karen,

I’m trying to use only those that replied ‘yes’ to certain variables (9 diff preschool settings) and recode them into a new variable (setting: formal vs informal). if all the data was under a single variable then I know i could just recode via grouping (ex 1-5 =1, 6-9=2) but since it’s not, i’m totally lost. where do I start?

thanks

Hi Naomi,

This kind of data manipulation can get complex, so it’s hard to say without a lot of detail (it’s all in the details).

But one trick is to code them all 0/1 where 0=no and 1=yes. Then summing them tells you how many yeses you have. Use the sum in an if…then statement.

You often have to create some sort of intermediary variable that you use in your recode, even if the sum doesn’t work.

Hi,

I have a questionnaire where a few items (measured on Likert scale) are supposed to measure the same factor,

e.g. 3 items are measuring job stress, 2 items are measuring social support.

Naturally, I’ve entered them separately to SPSS.

1. Should I somehow assign them to the same factor? If yes, then how?

2. What analysis should be used to find out the total effect (and separate) of those few items on that one factor their supposed to measure?

Sorry, if these seem like dummy questions I’ve so many more of them

Hi Simona,

Normally, you’d do a factor analysis to check if variables really are measuring the same factor and to understand their common and unique variance. However, you need a minimum of 3 variables per factor, so it’s best to have at least 5 per factor for the test. So I’m not sure you have the data to do it.

If you have many questions, it may be useful for you to set up a Quick Question Consultation. I’d be happy to go over them with you. It’s amazing what we can get done in an hour.

Hi, i would like to help me with an exercise. I have done the recode ”into a different variable” and the result on the output it’s fine, i mean that i have not done any mistace with the categories. But when i want to see the frequencies (analyse–> descriptive statistics–> frequencies) i can’t see the categories from the output. Specifically appears only the first and the second category of the variable.

DONT FORGET TO MENTION: this happens only with this variable. i can recode everyone else variable but not this one.

Please help me!

Hi Magia,

The only reason I can think of is if there weren’t any instances of those categories in the data.

I find that using the “Case Summaries” is a good way to debug recoding problems.

I am recoding some of my data into different variables – I’ve done a bit of it already and I’ve no problems with the basics. But now I need to do industrial amounts of recoding and I’m wondering if there’s a way of saving any time/ work – i.e. is there a copy and paste mechanism within the recoding function?

To explain, I have done a content analysis of a local newspaper. I wanted to find out what kind of people (sources) are quoted in articles. I have 9 identical categories for ‘Source’, which captured what kind of people were quoted in newspaper articles and also where geographically they were from. I have 10 geographical areas, and 20 types of person. That gives me 200 variables in the Source category. I have 9 identical Source categories (Source1, Source2 etc, as there could be many people quoted in an article).

I need to recode each of these Source categories twice so that I can group the variables firstly by geography, then by the type of person.

I have recoded Source1 for geography, which gives me a long list of variable numbers (eg 1->1, 11->1) – this list would be identical for my other categories, Source2, Source3 etc. Is there a way of copying the list to save my typing it all out each time? (Or I will be here for days!!!)

Thanks!

Rae

Ooh, never mind, I’ve figured it out! SPSS cleverly remembers all the recoding so you just have to go back to recode again, change the category names and, I guess, do it all in the same session so it doesn’t wipe the list.

Thanks anyway!

Rae

I’m having trouble recoding a variable consisting of 10-digit numbers into even and uneven. When defining old and new values is it possible to use a “joker” (old value: *********1 -> new value: 0, old value: *********3 -> new value: 0, old value: *********2 -> new value: 1 and so forth, recoding all the 10-digit numbers into 0’s and 1’s)

I obviously tried using * but it didn’t work.

Hi Kristine,

I know you can do something like what you’re trying to do with the substring function of a string variable. But I don’t know if that’s an option if it’s numerical.

There are many different ways to approach something like this, but I would be tempted to use the truncate function to do this.

If trunc(Variable/2) = Variable/2 Even=1.

If trunc(Variable/2) ~= Variable/2 Even=0.

I haven’t tested this (so it may not work as written), but the logic is that for an even number, if you divide by 2, there will be no remainder to truncate off. For an odd there will be. Look under Compute for the exact syntax of the function.

Hello,

After I recode a variable (scale) the correlation still comes out negative; What do I do next?

Hi, I’m new in SPSS. I don’t know how to activate a written syntax in spss.

ex:

RECODE API (Lowest thru 50=Good) (51 thru 100=Moderate) (101 thru 150=Unhealthy for Sensitive Group)

(151 thru 200=Unhealthy) (200 thru 300=Very Unhealthy) (301 thru Highest=Hazardous) (MISSING=NA)

INTO AQILH.

VARIABLE LABELS AQILH ‘Air Quality Index Health Level’.

EXECUTE

then ho it will work for my file or other file in future?

Thanks, Roya

Hi Roya,

Rather than use Good, Moderate, etc. for your new values, I would suggest using numerical values, like 1, 2, 3. You can do what you’re trying to do, but because they’re character strings, not numbers, you have to make a few changes.

So you’ll have to put each one within single quotes, so it would look like:

RECODE API (Lowest thru 50=’Good’) (51 thru 100=’Moderate’) etc.

You will also have to declare your new variable, AQILH as a string variable before you begin the recode. That one I don’t remember off the top of my head, so I’ll let you look it up.

Thank you Karen, I appreciate for very useful tips.

Now my problem really is:

Suppose I write a data file, then I want to create a new variable (recode),

how I should introduce syntax file to this data file? I mean how it identify my syntax file which is saved in any corner of my computer?

thanks in advance, Roya

Hi Karen,

I have seven complication variables (comp1 – comp7) each with dummy coding of “1” for “has complication” and “0” for “no complication”. I want to create a separate variable called “number of complications” that will show the cumulative frequency of complications from these 7 complications (0-7). How should I approach this?

Thank you very much

Hi Karen,

I have a gigantic file with a lot of subjects. I need to create a new variable that is dependent on certain subjects, in no logical order. So, for example, the new variable should be 0 for subjects 1013, 1025, 2001 and 3004, and should be 1 for subjects 1003, 1021, 2017 and 3012. I have the subject numbers sorted bij condition in an Excel spreasheet, so I could copy the numbers from there.

SPSS, of course, has the option to recode into new variable. However, I can not find a way to copy the subject numbers into the recode dialog. This means I have to recode for every subject number by hand. Is there a way to make life easier in SPSS? Or should I look into a macro for Excel?

Thanks in advance for any advice.

Hi Sid,

Is there a variable that is defining which subjects get which value of the new variable, or is it just certain subject numbers?

If you have the subject ids as a variable, you can definitely use them in the recode. This is a case where using syntax would be much, much easier. Also, think about whether using Compute would be easier than Recode.

For example, you could say ” If Subid=ANY(1013, 1025, 2001, 3004) (Newvar=0). That kind of statement.

Hi

I would like to recode an old variable (numeric) into a new variable (string) that is the label of the old variable. Is there a way to do this in spss (I am using spss 9)?

My old variable is a list of foods (codes) with variable labels. My new variable will be a list of foods (by name: labels of the old variable). I need to do this to facilitate control of some other variables depending on each food.

Yes. There’s a string button in the “Recode into Different Variables” dialog box.

There’s also a detailed section in the Command Syntax Reference to convert Numeric to String variables in syntax. I would start there.

Hi Karen,

I need a small help on of the recode.

actually we have 7 variables which have data

A B C D E F G – Variables

84 64 34 45 23 10 92 – Actual data

2 3 5 4 6 7 1 – Recode…(assigning highest rank)

we need these recodes into new variables. is this possible in the SPSS.

If so could you please let us know the syntax…

advance thanks for your help!!

Hi Kricks,

There is a Rank function in SPSS. I couldn’t give you the exact code without trying it, but look it up in the Command Syntax Reference.

Thanks Karen,

We have tried that one but it is assign rank in same variable..we need to compare all the columns and assign highest rank to specified column same as other variables…

A B C

90 50 80

We need like

A1 B1 C1

1 3 2

hello

I have a question that I Collected data on all children in household and inserted them as first, second,third…etc and faced difficulty of analysis.can you help me

Possibly, but I’d have to talk with you to get all the details. So consider a consultation or joining our membership.

hie

im new to spss, wanted help on how to rank mutiple responses not basing on their occurance but basing on there positions. I hope you help- im really stuck

Hello Karen,

I have 6 variables that are measured with 6-point Likert scale, however I would like to turn them into 2 variables, and did it according to your instructions:

1 thru 3 = 2 (disagree)

4 thru 6 = 5 (agree)

When I apply pie chart, one of the variables present all the data (n=162), however the remaining 5 are missing data. Besides, each of these variables are missing another amount of data. I am very confused. What could have caused this?

Thank you,

Anna

Hi

How I can use information in two columns in SPSS(e.g, schools and Grades) using SPSS RECORD option to code them in a different variable. For example, if a person is in school X and Grad Y is coded as 1, and the same for all other schools and grades.

Hi Noara,

You need to use an IF statement. If you’re in the menus, I think you may have to use COMPUTE instead of Recode. In the menus, there is a small box at the bottom of the Compute dialog window that says IF. You have to use that to say, for example

if school=1 and GradY=1 NewVariable=1.

Hi Karen,

Thank you so much for the reply.

I tried COMPUTE option but I kept getting this error message when I use IF command: “Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command”.

Is that possible that my variables are STRING? E.g., school column contains schools names and for Grades I have STRING G1, G2,…. and so on. Please note that I define my new variable as STRING using TYPE & LABLE OPTION. Any suggestion would be appreciated.

Thanks

Hi Karen,

Thank you so much for your previous reply.

I tried COMPUTE option but I kept getting this error message when I use IF command: “Incorrect variable name: either the name is more than 64 characters, or it is not defined by a previous command”.

Is it because my variables are STRING? E.g., school column contains schools names and for Grades I have STRING G1, G2,…. and so on. Please note that I define my new variable as STRING using TYPE & LABLE OPTION but still I am getting errors. Any suggestion would be appreciated.

Thanks

Hi, I each variable recorded as a human tooth. Each variable too is coded as 0=present, 1=Absent. I would like to combine all of the variables (teeth) so that I can run Chi Square analysis between sexes, over time etc for the total number of teeth in an individual’s mouth (each case). I can’t figure out how to combine them. It doesn’t seem to work when I try to sum them.

Help?

when i have an negative variable like destroyed ideas, can i code it by negative numbers?

-1, -2,-3, …

thank you

I could use a little help in SPSS. I exported my data into excel from an interviewing program, and uploaded it into SPSS. Then I realized that I forgot a question in the interview, luckily it is similar to another question so I am going to have the two variables be the same (ex. VAR1=Var2). Is there a way to write syntax or some kind of command that will go in, find the variable and make it the same as variable 2? Someone please help, if you need more explanation let me know.

Thank you!

Hi, I need to create a variable that is based on multiple lines (cases). for example, if I have 5 lines with identical case number, I want the new variable to code the first line (case) as 1 and the remaining 4 lines (cases) as 0. Is it possible in SPSS? would appreciate guidance.

Thanks!

Hi Keren,

Yes, you can do it in syntax using the lag function.

This is how I would do it. Note that I’m not testing this code, but it should put you on the right track.

I’m assuming your case variable is caseid and new variable is newvar.

sort cases by caseid.

if caseid~=lag(caseid) newvar=1.

if caseid=lag(caseid) newvar=0.

I would look up lag in the Command Syntax Reference to get more examples.

Hi there

Desperately trying to work out why, after following several different tutorials on completing reverse-coded variable values, “Execute” keeps coming up in the output syntax after I have recoded all the variables and pressed, “Continue” and “Ok”…and my variables stay the same, i.e. no reverse-coding achieved! I have no idea why it’s not working. Any help would be super appreciated. Thanks.

HI Mary,

Are you running the Execute command as well as the recode? The recode won’t happen until you run Execute. Or are you just using menus?

I have a problem in recording the growth value in SPSS as some of these values are negative for example -.085 What can I do.

Thanks

how can i record negative values on SPSS

I need your help in just a simplest manner teach me to re code data into different variable using if cases, if u could do this by sending to me a very easiest example it will be great to me!

thank you.

Hi Maren,

I would start by plotting it and checking your recode. Start here:

http://www.theanalysisfactor.com/steps-to-take-when-your-regression-or-other-statistical-results-just-lookwrong/

{ 1 trackback }