This article describes how to apply different filters to each variable in a Pick Any question. This is sometimes needed when each category in a Pick Any question needs to have different bases.
If the question you want to filter by has separate categories for each filter, the QScript Filter One Question By Another will do what you need and is frequently the best place to start. To run that QScript go to Automate > Browse Online Library > Filter > Filter One Question by Another. If the QScript doesn't produce what you need, try the process below.
Method 1: Using a Rule
You can filter rows and columns of a table using Filtering - Apply Filters to Columns or Rows. However, this will turn off statistical testing. If you require statistical testing, see Method 2.
Method 2: Creating Filtered Variables
The example below shows you how to construct a new copy of a Pick Any question in this way using the Cola.Q example project from your Examples folder installed with Q. This same approach can be used with other question types. The question will be Q9. Cola weekly, and each category in the question will be filtered by respondents prefer that particular brand, according to Preferred cola. To test this example you should:
- Open C:\Program Files\Q\Examples\Cola.Q (this may be located on a different place on your computer depending upon how Q was installed).
- Go to the Variables and Questions tab.
- Highlight all of the variables from the Pick Any question Q9. Cola weekly.
- Right-click and select Copy and Paste Questions > Linked. This will create a new copy of the question below.
- Right-click on the first variable in the new question (Coca Cola) and select Edit Variable. (Make sure that you only have the first variable selected.)
- Change the text in the Expression box to the appropriate expression for Coca Cola that is listed below.
- Click OK.
- Repeat the previous three steps for each variable in the question, substituting the appropriate Expression from below.
- Change the entry in the Question column to Q9. Cola weekly - Filtered by Preferred Cola.
- Coca Cola
if (PreferredCola == 9 Q9_A_3; else NaN;
- Diet Coke
if (PreferredCola == 1) Q9_B_3; else NaN;
- Coke Zero
if (PreferredCola == 2) Q9_C_3; else NaN;
if (PreferredCola == 3) Q9_D_3; else NaN;
- Pepsi Light
if (PreferredCola == 4) Q9_E_3; else NaN;
- Pepsi Max
if (PreferredCola == 5) Q9_F_3; else NaN;
- The if statement in each formula checks the relevant variable from Preferred Cola to see if the respondent is prefers that brand.
- The second line assigns a missing value, or NaN. This removes the respondent from the base for this variable, effectively filtering them.
- In this example you can apply the new filter for the first variable and then right-click it and choose Insert Ready-Made Formulas: Use as Template for Replication as a shortcut. However this may not apply in all cases as it relies on a common structure for the two questions involved. See Use as Template for Replication for more details on using this feature.