Introduction
A common data cleaning problem involves changing the data for a variable, or set of variables, based on a rule of some kind (i.e., condition). For example, there may be a desire to recode brand awareness data to make it consistent with brand usage data (e.g., if people have indicated they are not aware of a brand that they purchased, you might decide to change their awareness response to 'Aware').
Method
The steps on this page can be reproduced using c:\Program Files\Q\Examples\cola.Q (this may be located on a different place on your computer depending upon how Q was installed).
There are a variety of different ways of conditionally recoding into a new variable. In general, the easiest way to do this for a single variable is to:
- Select the variable in the Variables and Questions tab.
- Right-click on the variable and select Copy and Paste Question(s) > Linked. A new variable will appear with a modified name based on the original variable. For example, the linked copy of Q3 will be named Q3_L.
- Right-click on the newly-created variable and select Edit Variable.
- Modify the expression as required. For example, if a respondent answered a 1 in Q2 they would be given a 2 in Q3, and otherwise their answer is unchanged, you would use the following Expression: if (Q2 == 1) 2; else Q3.
Next
How to Recode Into a New Variable
How to Use Search/Replace to Conditionally Recode Lots of Variables