How to Conditionally Recode into a New Variable

From Q
Jump to: navigation, search
Related Online Training modules
Javascript If Statements
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:

  1. Select the variable in the Variables and Questions tab.
  2. 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.
  3. Right-click on the newly-created variable and select Edit Variable.
  4. 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.

See also

Personal tools
Namespaces

Variants
Actions
Navigation
Categories
Toolbox