Developer Documentation Library > Scripting > mrScriptMetadata User's Guide > mrScriptMetadata reference > Field definitions > Categorical loop
 
Categorical loop
A loop defines a set of questions that are to be asked more than once. In a categorical loop, the number of times that the loop is to be repeated (and therefore the number of times that the set of questions in the loop are to be asked) is controlled by the categories in a category list. For example, the set of questions can be asked for each product in a product list. In technical terms, a categorical loop is an array of questions in which the index into the array is based on a category list.
The questions in the loop can be asked sequentially (one after the other) or simultaneously (for example, in a grid).
Syntax
For clarity, each item is shown on a separate line, and optional items are indented, See also Syntax conventions.
field_name
   [ "field_label" ]
  [ [ <properties> ] ]
  [ <styles and templates> ]
loop
<categories>
fields
  [ "iteration_label" ]
( <field> (; <field> )* [;] )
  [ row | column ]
  [ expand ]
  [ grid ]
Parameters
field_name, field_label
See Names and labels for more information.
<properties>
You can define custom properties for your field to store information that is not directly supported by the Metadata Model (MDM). See Custom properties for more information.
<styles and templates>
You can use styles and templates to define the appearance of a question. See Styles and templates for more information.
<categories>
Defines the category list that controls the iterations. This is called the controlling category list. You define it in the same way as the category list for a Categorical question. (The categories in this list are called subquestions in some UNICOM Intelligence products, such as UNICOM Intelligence Interviewer - Paper.)
iteration_label
Defines a label that will be displayed for each iteration when the questions in the loop are asked sequentially. See Names and labels for more information. To include the current controlling category's label in the iteration label, use an index insertion: see Label text insertion.
<field>
Defines a question inside the loop. See Field definitions for more information.
row
Specifies that the categories in the controlling category list are to be displayed as rows when the loop is displayed as a grid. Note that this is the default behavior if neither the row or column keywords are specified.
column
Specifies that the categories in the controlling category list are to be displayed as columns when the loop is displayed as a grid.
expand
The UNICOM Intelligence Data Model can represent the case (response) data collected using a loop in a “flattened” format, a hierarchical format, or in both formats. Which format is used depends on how you define the loop and the format in which the case data is being stored (because the capabilities of the various CDSCs vary). By default, loops are defined as levels, which means that the case data is stored in a hierarchical format only. However, you can use the expand keyword to specify that it should be stored in a flattened format. For example, you would need to do this if the case data is being stored in an SPSS .sav file, because the SPSS SAV DSC does not support a hierarchical view of the data. If the DSC supports both a hierarchical and a flattened view of the data (such as RDB DSC 2 does), using the expand keyword means that the data is represented in both formats, provided the loop is not nested in another loop.
For more information about hierarchical data, see Hierarchical data in the MDM.
grid
Defines that the loop is to be displayed as a grid question--for example, for use in an UNICOM Intelligence Interviewer - Paper questionnaire. However, you must make sure that the loop is suitable for display as a grid question: it must contain only simple questions and not any nested loops, blocks, or compounds.
Make sure that you specify the grid keyword if you want UNICOM Intelligence applications and components to recognize that the loop is a grid. Some UNICOM Intelligence tools treat a grid differently from a loop that is not a grid.
Remarks
For more information about writing categorical loops in interview scripts, see Categorical loops.
Examples
Categorical grid question
You can use categorical loops to create categorical grid questions (sometimes referred to simply as grid questions). These are frequently used to ask respondents to choose a rating on a predefined scale for a number of products in a list. Typically, a categorical grid question has one categorical question inside the loop.
This example creates one of the grid questions in the Museum sample questionnaire using two defined lists:
Galleries defines the controlling category list.
RatingCategories defines the category list for the categorical variable inside the loop.
Galleries define
{
Dinosaur,
Conservation,
Fish "Fish and reptiles",
Fossils,
Birds,
Insects,
Whales,
Mammals,
Minerals,
Ecology,
Botany,
Origin "Origin of Species",
Human "Human biology",
Evolution,
Wildlife "Wildlife in danger"
};
RatingCategories define
{
Not "Not at all interested",
NotParticularly "Not particularly interested",
NoOpinion "No opinion",
Slightly "Slightly interested",
Very "Very interested"
};
RatingLoop "How interested were you in the museum displays?" loop
{
use Galleries
} fields
(
Rating categorical [1]
{
RatingCategories use \\.RatingCategories
};
) expand grid;
This illustration shows the RatingLoop grid question. (Its exact appearance depends on the mode of interviewing and the formatting options applied.)
This graphic is described in the surrounding text.
The expand keyword has been used to specify that the case data is to be stored in a flattened format. The UNICOM Intelligence Data Model uses variable instances (VariableInstance objects) in the metadata to map a question to the columns that store the responses (case data) in the VDATA virtual table. For this example there will be one categorical variable instance for each of the categories in the controlling category list (Dinosaur, Conservation, and so on.).
Numeric grid question
You can use categorical loops to create numeric grid questions, in which the question(s) inside the loop are numeric, rather than categorical.
In this example, also from the Museum sample questionnaire, there is one numeric question inside the loop, and it reuses the Galleries defined list.
Galleries define
{
Dinosaur,
Conservation,
Fish "Fish and reptiles",
Fossils,
Birds,
Insects,
Whales,
Mammals,
Minerals,
Ecology,
Botany,
Origin "Origin of Species",
Human "Human biology",
Evolution,
Wildlife "Wildlife in danger"
};
OrderLoop "What do you remember seeing first, second,
third, and so on? (ENTER 1 FOR THE GALLERY YOU SAW FIRST,
2 FOR THE GALLERY YOU SAW SECOND AND SO ON.)" loop
{
use Galleries
} fields
(
OrderOfViewing "Order of viewing" long [1 .. 16];
) expand grid;
This illustration shows the OrderLoop numeric grid question. (Its exact appearance depends on the mode of interviewing and the formatting options applied.)
This graphic is described in the surrounding text.
In this example, the expand keyword has been used again to specify that the case data should be flattened. When a numeric loop is flattened, there is one numeric variable instance for each cell in the grid. However, in this example, the number of variable instances corresponds to the number of categories in the controlling category list, because there is only one numeric variable inside the loop.
Numeric grid question that has several numeric questions inside the loop
This example, from the Short Drinks sample questionnaire, creates another numeric grid question. However, this time the categorical loop contains five numeric questions, each one representing a day of the week.
DrinksList define
{
Tea,
Coffee,
Carbonated "Carbonated soft drinks",
Milk,
Fruit "Fruit and vegetable drinks",
PSD "Powdered soft drinks",
Water
};
NumberOfDrinks "Can you tell me how many of the following drinks you consumed each day last week? WRITE IN THE NUMBER OF DRINKS CONSUMED EACH DAY" loop
{
use DrinksList
} fields
(
Monday long [0 .. 100];
Tuesday long [0 .. 100];
Wednesday long [0 .. 100];
Thursday long [0 .. 100];
Friday long [0 .. 100];
) expand grid;
This illustration shows the NumberOfDrinks numeric grid question. (Its exact appearance depends on the mode of interviewing and the formatting options applied.) This time the expand keyword has not been used, so the data will be represented hierarchically only. However, if it were to be flattened, there would be 35 numeric variable instances because there are 35 cells in the grid.
This graphic is described in the surrounding text.
Categorical grid question that has more than one categorical question inside the loop
This example defines a categorical loop that has two related categorical questions nested inside the loop. A question could be defined in this way to divide the responses for a large category list into different variables. In this example, a different variable is used for the positive and negative responses.
Positive define
{
NoProb "No Problems - no cause to complain",
GoodService "Good Service",
GoodBreakdown "Provides breakdown of expenses",
CardsAccept "Wide acceptance of cards",
PosOther "Other positive" other
};
Negative define
{
Slow "Slow to respond/poor service",
LimitedCards "Limited acceptance of cards",
Inaccurate "Inaccuracies of bills",
CostTooHigh "Costs too high/expensive",
CustContact "Not enough customer contact/service",
NegOther "Other negative" other
};
Services "Give your impressions of each service" loop
{
Electricity,
Gas,
Telephone
} fields
(
PositiveResponses categorical
{
Positive use \\.Positive
};
NegativeResponses categorical
{
Negative use \\.Negative
};
) expand grid;
This illustration shows the Services grid question. There are six categorical variable instances, because although there are only three categories in the controlling category list, there are two categorical questions inside the loop.
This graphic is described in the surrounding text.
Categorical loop containing different question types
This example takes the previous example a step further and includes a numeric question inside the loop.
Positive define
{
NoProb "No Problems - no cause to complain",
GoodService "Good Service",
GoodBreakdown "Provides breakdown of expenses",
CardsAccept "Wide acceptance of cards",
PosOther "Other positive" other
};
Negative define
{
Slow "Slow to respond/poor service",
LimitedCards "Limited acceptance of cards",
Inaccurate "Inaccuracies of bills",
CostTooHigh "Costs too high/expensive",
CustContact "Not enough customer contact/service",
NegOther "Other negative" other
};
Services "Give your impressions of each service" loop
{
Electricity,
Gas,
Telephone
} fields
(
PositiveResponses categorical
{
Positive use \\.Positive
};
NegativeResponses categorical
{
Negative use \\.Negative
};
Spent "How much did you spend?" long [0 .. 99];
) expand grid;
This illustration shows the loop displayed as a grid. Like the previous example, there are six categorical variable instances. However, there are also three numeric variable instances.
This graphic is described in the surrounding text.
See
Field definitions