Creating New Variables Using Recode
Sometimes we want to recode a variable into subgroups or categories. For example, we might want to create a variable with data on age recoded into age groups.
Simple Recode (2 Groups)
Recoding Variables Using Nested IF Functions
It is possible to recode variables into 3 or more groups in only two steps using a formula containing a series of nested IF function statements. The formula tells Excel to perform multiple logical functions in relation to recoding data. If you understand the logic of IF statements, you can recode your data into 3, 4, 5 or more groups using only one formula containing a series of nested IF statements.
Complex Recode (3 groups) Using Nested IF Statements
In cell V2 type the formula =IF(J2<10,1,IF(J2<18,2,3)) Press Enter.
A number (1,2, or 3) should appear in cell V2. The formula has given Excel this complex set of instructions: Look at cell J2 (the column where Age is located). If the value in cell J is less than 10, place a 1 in cell V2. If the value in cell J2 is greater than 10 but less than 18, place a 2 in cell V2. If the value in cell J2 is 18 or greater than 18, place a 3 in cell V2. Parentheses are used to nest the second IF statement within the first IF statement, so that Excel can read the formula and understand that it is supposed to carry out a series of operations based on a logical series of If-Then-Else statements.
If you understand the logic and symbols used to construct formulas using nested IF statements, you can recode any variable into 3 to 8 categories by typing the formula and copying it to the other cells in the data file.
Complex Recode (4 groups) Using Nested IF Statements
In cell W2 type the formula =IF(J2<7,1,IF(J2<9,2,IF(J2<18,3,4)))
Press Enter.
A number (1,2,3, or 4) should appear in cell W2. The formula has given Excel this complex set of instructions: Look at cell J2 (the column where Age is located). If the value in cell J2 is less than 7, place a 1 in cell W2. If the value in cell J2 is greater than 7 but less than 9, place a 2 in cell W2. If the value in cell J2 is greater than 8 but less than 18, place a 3 in cell W2. If the value in cell J2 is 18 or greater than 18, place a 4 in cell W2. Parentheses are used to nest the second and third IF statements within the first IF statement, so that Excel can read the formula and understand that it is supposed to carry out a series of operations based on a logical series of If-Then-Else statements.
If you understand how to construct nested IF statements, this is a quick, two-step process for recoding variables. Excel allows you to construct formulas that contain up to seven nested IF statements.
Return to the