Reporter > Using variables > Variable type overview > Loops and grids > Loops
 
Loops
The number of times the question or set of questions is to be asked can be controlled in three main ways:
By the categories in a category list. For example, "For each brand in the following list, please answer the following..."
By a numeric expression that has a known upper limit. For example, "For each of the first three journeys you described earlier, please answer the following..."
By a numeric expression that has an unknown upper limit. For example, "For each drink you consumed last week, please answer the following..."
Each of these constructions is a loop that defines the question or set of questions and the number of times they are to be asked (or, in more technical terms, the number of times the loop is to be iterated). When you analyze the data in UNICOM Intelligence Reporter, whether the questions in the loop were asked simultaneously as a grid or sequentially (one after the other) is not really relevant.
Example numeric loop number
Consider the following loop, which is presented here in a grid-like format:
This loop contains two questions, Name and Gender, which are asked up to 6 times. This means that the loop has 6 iterations.
When the response data is presented in a non-hierarchical form, it is "flattened" and a separate variable stores the responses to each question in each possible iteration. In this example, there would be 12 variables (2 * 6). For example, if the loop is called MyLoop, the following variables would store the responses:
MyLoop[1].Name
MyLoop[2].Name
MyLoop[3].Name
MyLoop[4].Name
MyLoop[5].Name
MyLoop[6].Name
MyLoop[1].Gender
MyLoop[2].Gender
MyLoop[3].Gender
MyLoop[4].Gender
MyLoop[5].Gender
MyLoop[6].Gender
These are the full names of the variables and they are constructed from the names of the loop and the questions inside the loop. Brackets ([ ]) are used to indicate an iteration and a single period (.) to indicate a parent/child relationship.
This method of representing hierarchical data is simple and effective. However, it has some disadvantages, the most obvious one being that the number of variables is fixed. In our household example, this means that storage space is reserved for the responses of the six individuals in each household even though many households have fewer people. Conversely, responses cannot be stored for any additional people in large households. Another disadvantage is that performing summary calculations on the data can be difficult.
Representing the case data hierarchically can be more flexible and provides advantages during analysis. The loop is then considered a level and the responses to the questions in the loop are stored in a separate hierarchical table named after the loop. In this example, the hierarchical table would contain two variables, one for each of the questions in the loop, and would store the responses to each iteration in a separate row. The full names of these variables would be:
MyLevel[..].Name
MyLevel[..].Gender
Notice that two periods (..) are used in place of an iteration number, to indicate all iterations.
See also
Loops and grids