How to Conditionally Recode into a New Variable
|Related Online Training modules|
|Generally it is best to access online training from within Q by selecting Help > Online Training|
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).
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 (see See also at the botton of this page). 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 it and select Copy and Paste Question(s) > Linked. A new variable will appear with a name modified based on the old 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 you want to change answers to Q3 based on answers to Q2, such that if people answered a 1 in Q2 they would be given a 2 in Q3 but otherwise their answer is unchanged, you would use the following Expression: if (Q2 == 1) 2; else Q3.
- How to Use Search/Replace to Conditionally Recode Lots of Variables for a modification of this method to be used when changing lots of variables.
- Rebasing Questions Using a Condition.
- Changing data (i.e., changing a respondent's values).