Desktop User Guides > Professional > Interview scripting > Writing interview scripts > Repeated questions > Categorical loops based on answers to previous questions
 
Categorical loops based on answers to previous questions
Often you want to ask a question for each response given to an earlier question; for example, in a brand awareness test, you might ask respondents to name brands they have seen advertised and then, for each of those brands, ask what type of advertising was seen or heard and where.
The way to do this is to define the repeated question in the metadata section as if you were going to ask the question for all brands, not just those mentioned by the respondent. Then, in the routing section, you define a filter that restricts the brand list to those mentioned, and then ask the question in the normal way.
You can also create numeric loops: see Numeric loops.
Here is the metadata section for some insurance advertising awareness questions:
InsuranceCompanies define
{
RedWhiteBlue "Red, White, Blue Insurance",
InsuranceToGo "Insurance To Go",
WhistleHope "Whistle and Hope",
BestDeals "Best Deals",
CloverBenCo "Clover Ben and Co"
};
Adverts "Which insurance Companies have you seen or heard
advertised during the last month?" categorical [1..]
{
use InsuranceCompanies
};
Company "Company loop" loop
{
use InsuranceCompanies
} fields (
AdvertType "What type of advertising did you see/hear for
{@Company}?" categorical [1..]
{
TV, Radio, Newspaper, Magazine, Billboard
};
WhereAdvert "Please specify exactly where you saw/heard the
advertising (e.g., which TV channel, which magazine)" text;
) expand;
The Company loop is set up to ask the questions for each item in InsuranceCompanies, but you want to restrict this to only the companies mentioned at Adverts. You do this by defining a filter in the routing section as follows:
Adverts.Ask()
Company.Categories.Filter = Adverts
Company[..].Ask()
The filter statement tells the interviewing program to filter the categories held in Company so that they are the same as the answers given to Adverts. For more information, see Filtering categorical response lists.
If the respondent saw advertising for Insurance To Go and Clover Ben and Co, the loop is repeated twice with the page for the first iteration looking like this:
Example output for a loop based on response to a previous question
This graphic is described in the surrounding text.
See also
Repeated questions