Bringing data to a common unit
Problem
You want to bring to a common unit of measurement numeric data which was collected on different units.
Solution
There are two possibilities:
Discussion
First, a note of clarification on the actual problem. This recipe discusses the situation where numeric data was collected (e.g., one's weight or one's salary) which requires a numeric value as well as a unit of measurement (e.g., inches vs. centimiters, dollars per hour, per week, per month), typically collected using a unit-type question. The questionnaire designer wants to calculate a unique value which will bring all responses to a common unit (e.g., centimiters or dollars per year).
If the unit multipliers are integers, it is possible to assign the multiplier as the category code for the unit and to simply multiply this code with the numeric value supplied. For example:
If the unit multipliers are not integers (a limitation of answer category codes), use a calculation and the ternary operator (the "implicit if" operator). For example: