Recoding simple and two-level loops with edits
Download the example QEX from the table below to test the logic in AskiaDesign, and adapt the examples to your needs.
File | Compatibility | Description |
KB_Askia_recode_loop.zip | 5.3.3 and above | Using the "Iteration" keyword to easily identify loop iterations in a scripted logical condition. |
Goal
Researchers often need to recode collected data (during of after the data collection). The difficulty of this operation varies depending on the structure that was chosen for the source data and the target recode.
In this example, we'll focus on a more advanced one, and post-code two grid questions that use the same 5-point scale into one.
The simple level loop repeatedly asks the respondent to rate three different flights on the 5-point scale (Excellent - Good - Neutral - Rather Poor - Poor).
Here's how it is often displayed at the analysis level:
The two-level loop repeatedly asks the respondent to rate four services, provided by two different hotels (for a total of eight questions), on the same scale.
At the analysis level :
After data collection, the researcher asks the survey designer to arrange the data into one summary table.
The summary table shall have 11 rows (the 8 service ratings + the three flight ratings) and five columns (the 5-point scale). Let's name it "loop_recode_all".
Desired output at the analysis level:
Recoding the data
First, the recode structure needs to be added in AskiaDesign. We want the data to be recoded as a simple grid, which takes the form of a one-level loop in the questionnaire structure.
Punching the values
Now that the structure is set up and can receive the data, we need to "punch" the values into this loop.
As usual for re-coding tasks, a "set value" filter that is used as an "edit" will be used. The filter will run after "loop_recode" and will set the value of the "recoded_scale" variable.
Since the basic GUI interface won't be powerful enough for this particular recode, a scripted value will be punched.
At this point, you should open the QES in AskiaDesign to review the script.
1) Recoding the two-level loop (the hotels ratings) :
The first four iterations of the recode loop (hotel 1 - service 1, hotel 1 - service 2, hotel 1 - service 3, hotel 1 - service 4) - are dedicated to the values of the service rating for the first hotel.
If loop_recode_all.CurrentIteration has {1 to 4} then
return scale_service.Iteration(loop_hotel:1,loop_services:loop_recode_all.CurrentIteration)
Here, the first four iterations of the recode loop are punched depending on the values of the four service ratings for the first hotel.
The correct data is fetched by referencing the first iteration of the hotel loop as a parameter in the "Iteration" method, and associating the current iteration of the recode loop to the service loop.
recoded_scale[1] = 1st service rating
recoded_scale[2] = 2nd service rating
recoded_scale[3] = 3rd service rating
recoded_scale[4] = 4th service rating
Then the same process is used for the next four iterations of the recode loop (related to the four services of the second hotel).
elseif loop_recode_all.CurrentIteration has {5 to 8} then
return scale_service.Iteration(loop_hotel:2,loop_services:(loop_recode_all.CurrentIteration-4))
The data is fetched by referencing the second iteration of the hotel loop, and then there is a offset of -4 in the index of the recode loop so that we get the following output:
recoded_scale[5] = 1st service rating
recoded_scale[6] = 2nd service rating
recoded_scale[7] = 3rd service rating
recoded_scale[8] = 4th service rating
2) Recoding the one-level loop (flight ratings) :
This one is easier, because the data is only nested under a single loop. Therefore, the "Iteration" method will only need one parameter to correctly fetch the data - the index of "Loop_flight".
elseif loop_recode_all.CurrentIteration has {9 to 11} then
return scale_flight.Iteration(loop_flight:loop_recode_all.CurrentIteration-8)
The "-8" offset is needed so that data contained in the first iteration of "loop_flight" is recoded in the 9th iteration of "loop_recode".
recoded_scale[9] = 1st flight rating
recoded_scale[10] = 2nd flight rating
recoded_scale[11] = 3rd flight rating
Running the edit in AskiaTools will activate the filter and punch these values for all collected interviews.