You are on page 1of 6

Recoding

The “if” command


RECODING
• Recoding Categorical Variables
• Select, copy, find-replace, enter value to replace, enter replace value and
replace all.

• Recoding Numerical variables into Categorical variable


• Use “IF” function with “AND” or “OR”

• IF function
IF with only one condition
• Grades file
• Find out if a student passed/failed based on percentage

=IF(T2>50, "Pass", "fail")


IF with “AND” conditions
• Assigning Grade “D”
• The conditionality will be the first to feature after the bracket

=IF(AND(T2>=50, T2<70), "D","")

=IF(AND(T2>=50, T2<70), "D",IF(AND(T2>=70,T2<80), "C", ""))

• Note that the closed brackets must equal the open brackets

Q1. Assign all grades, along with “fail” for those with marks below 50.
Solution

=IF(AND(T2>=50, T2<70), "D",IF(AND(T2>=70,T2<80), "C", IF(AND(T2>=80, T2<90), "B", IF(T2>=90, "A", IF(T2<50, "Fail")))))

Note the number of brackets

Q2. Convert the grades into numbers (1 to 5).


Q3. Use the “or” condition to get the following categories
Merit: If grade is A or B
Pass without merit: If grade is C or D
Fail: if grade is “Fail” or “F”, whichever you have selected
Solutions

Sol2.
=IF(AA2="A",1, IF(AA2 = "B",2, IF(AA2 = "C",3, IF(AA2 = "D",4, IF(AA2 = "Fail",5)))))

Sol3.
=IF(OR(AA2="A", AA2 = "B"), "Merit", IF(OR(AA2="C", AA2="D"),"pass without merit", AA2))

You might also like