Recode

Transform > Compute > Recode

 

If you have data that is coded incorrectly (for example, contains incorrect wording), you can quickly recode it so it adheres to a consistent format. You can also use recode to replace missing or empty values.

Recode reassigns the values of existing variables into new values for a new variable.

You can recode numeric variables into factor variables and vice versa

You can recode old values into new values

 

Dialog box items

Variables:
List of variables to be recoded. Check the variables you want.

Factor to Numeric:
Allows you to create numeric variable from a given categorical variable.

oBoolean: Create a boolean column for each separate value of the selected column.

oFuzzy: Create a fuzzy column for each separate value of the selected column.

oIndex: Create an integer column for each separate value of the selected column.

Numeric to Factor:
Allows you to create new categorical variables from numeric (continuous) variables. The three options, Cut Points, Binning, and Unique Values allow you to create categorical data from the selected column in three different ways.

oCut Points: Create categories based on specific values. You can Add, Change or Remove values. The list is automatically sorted.

oBinning: Create bins of equal size on range or count. Select from the options Range or Count as the method for determining the bins.

oUnique Values: Create a separate level for each unique value of the selected column (Automatic option) or list (Manual option).

Old value into New value:
You can define values to recode.

oOld value: The value(s) to be recoded. You can recode single values, ranges of values, and missing values from the list. Leave blank to indicate a missing value. Ranges include their endpoints and any must be numeric.

oNew value: The single value into which each old value or range of values is recoded. New values can be numeric or string. The new value and old value may be in a different data type.

oAdd, Change, Remove: The list of specifications that will be used to recode the variables. You can add, change, and remove specifications from the list.

 

Example of creating boolean variables

The following example is used to show you how to split a categorical variable into several boolean variables. Data are a random sample of Montana residents.

Source: http://lib.stat.cmu.edu/DASL/Datafiles/montanadat.html

1.Open the DataBook summary.vstz

2.Select the sheet Montana

3.Highlight the column that contain data you would like to recode, in this example, the column GENDER

4.Choose the tab Transform, the group Compute and the command Recode

5.Close the recode editor by clicking OK.

You now have two new columns. The column called male contains 1 if the resident is a man, and empty otherwise.

Similarly, the column called female contains 1 if the resident is a woman , and empty otherwise.

GENDER

 

female

male

male

 

 

1

male

 

 

1

male

 

 

1

female

 

1

 

female

 

1

 

male

 

 

1

female

arrow_rigth

1

 

male

 

 

1

female

 

1

 

male

 

 

1

female

 

1

 

female

 

1

 

male

 

 

1

male

 

 

1

male

 

 

1

male

 

 

1

 

 

Example of creating categories using cut points

The following example walks you through the use of cut points to create a categorical variable. Data come from reg.vstz and are a random sample of Montana residents.

Source: http://lib.stat.cmu.edu/DASL/Datafiles/montanadat.html

The sheet Human has a column called Weight. Suppose you want to create two weight classes, one class for residents of less than 128 pounds, and one class for residents of more than 128 pounds.

1.Open the DataBook reg.vstz

2.Select the sheet Human

3.Highlight the column that contain data you would like to recode, in this example, the column Weight

4.Choose the tab Transform, the group Compute and the command Recode

5.Select group Numeric to Factor and the tab Cut Points

6.You can Add, Change or Remove the cut points from the list.

7.Close the recode editor by clicking OK.
The datasheet contains a new categorical column called C_Weight. This factor contains two levels, [97.9019 ; 128.42905[ and [128.42905 ; 158.9562] .

 

Example of recoding old values into new values

Suppose you want to replace the empty cells of male and female columns created in the previous section by the number 0:

1.Choose the tab Transform, the group Compute and the command Recode

2.Check the variable female

3.Select group Old value into New value

4.In New value, enter 0, and then click Add

5.Check the variable male

6.Select group Old value into New value

7.In New value, enter 0, and then click Add

8.Click OK.
The new columns C_female and C_male are filled with values where empty cells are replaced by 0.

 

 

female

male

 

C_female

C_male

 

1

 

0

1

 

1

 

0

1

 

1

 

0

1

1

 

 

1

0

1

 

 

1

0

 

1

 

0

1

1

 

 

1

0

 

1

arrow_rigth

0

1

1

 

 

1

0

 

1

 

0

1

1

 

 

1

0

1

 

 

1

0

 

1

 

0

1

 

1

 

0

1

 

1

 

0

1

 

1

 

0

1