Crosslists create a single list of all possible permutations from two or more lists using the crosslists
tag.
set list: GENDER
1. Male
2. Female
3. Non-binary
set list: AGE
1. 18 - 34
2. 35 - 54
3. 55 and above
set list: GEN_AGE
crosslists: GENDER, AGE
Tip! When creating a crosslist for a quota, use the cross by
tag instead.
Details
- To create a crosslist, use a
set list
widget with thecrosslists
tag and specify which lists will be used to define the new, combined list, separated by a comma. - The crosslist must be defined after its component lists in the survey source.
- The number of items that a crosslist will have can be determined by multiplying together the number of items in each list being crossed.
- Crosslist option IDs are created by concatenating the original list IDs. The default separator for each concatenated option ID is an underscore, and a comma for each new option text. To override these defaults, use the
crosslist id separator
andcrosslist text separator
tags. - All conditions and option decorator data are also preserved, so they can be used by any questions or variables which reference the crosslist.
- Crosslists inherit and combine
desc
decorators, which can help simplify labels for rows/columns. - Crosslists support the ability to include and exclude options from the lists being crossed, (e.g.,
crosslists: PURCH, AGE-[1,2]
). - Crosslist quotas are displayed in a grid in the Quotas applet, where the first list is used for the rows and the remaining list(s) are used for the columns.
- Add
crosslist tile: n
to display crosslists as standard quota rows, instead of a table format.
Caution! Be cautious when creating large crosslists, as they can lead to complex and extremely large data structures.
Determining list order
Crosslists display combinations in a defined order. Each element from the first list is paired sequentially with all elements of the second list, listed in numerical order by the element IDs. This pattern continues until all elements of the first list have been paired with all elements of the other list(s).
For example, the code above produces the following list:
1_1. Male, 18 - 34
1_2. Male, 25 - 54
1_3. Male, 55 and above
2_1. Female, 18 - 34
2_2. Female, 25 - 54
2_3. Female, 55 and above
3_1. Non-binary, 18 - 34
3_2. Non-binary, 35 - 54
3_3. Non-binary, 55 and above
Additional examples
Modifying the ID and text separators
The crosslist id separator
tag alters how IDs in a crosslist are separated in the data. By default, the option ID from the GEN_AGE list used above is 1_1
. However, applying crosslist id separator:
would change the ID format to 11
.
Similarly, the crosslist text separator
tag alters how option (or desc
decorator) texts are separated in the data. By default, the option text from the GEN_AGE list appears as 'Male, 18 - 34'. Using crosslist text separator: ~
would change the text format to 'Male~ 18 - 34'.
See the updated code below for the changes.
set list: GENDER
1. Male
2. Female
3. Non-binary
set list: AGE
1. 18 - 34
2. 35 - 54
3. 55 and above
set list: GEN_AGE
crosslists: GENDER, AGE
crosslist id separator:
crosslist text separator:~
Tip! Apply the HTML for "non-breaking space" (
) to force a space between the first text and ~
.
Referencing question IDs instead of lists
It is possible to build crosslists from questions rather than lists. This reference to a question is called question-label shorthand. It's an abbreviated way to write a conditional statement meaning "all options selected at QX."
In the example below, AGEGENLIST uses question-label shorthand to reference Q4 and Q5. Since both of these questions are single select questions, only one option will be selected from each. The crosslist will then produce only one viable combination of options from Q4 and Q5.
The use of a crosslist in a quota is explained in the next example.
set list: GEN 1. Male 2. Female
3. Non-binary set list: AGERANGES 1. 18 - 34 2. 35 - 54 3. 55 and above 4. What is your gender? type: radio optsfrom: GEN 5. What is your age? type: radio optsfrom: AGERANGES set list: AGEGENLIST crosslists: Q4, Q5 AGEGEN. QUOTA | Age-Gender type: quotas optsfrom: AGEGENLIST
Creating a crosslist quota
Here's a crosslist quota using the crosslists
tag. This method creates an independent list before applying it to the quota. It's useful if you need to reuse the list in multiple places, including respondent-facing questions, or if you need to leverage the crosslist id separator
and crosslist text separator
tags.
set list: GENDER
1. Male
2. Female
3. Non-binary
set list: AGE
1. 18 - 34
2. 35 - 54
3. 55 and above
set list: GEN_AGE
crosslists: GENDER, AGE
crosslist text separator: -
crosslist id separator:
GENXAGE. Gender x Age Quota
type: quotas
optsfrom: GEN_AGE
Understanding crosslists and conditions
Conditions are defined using curly braces to enclose an "if statement" (e.g., {if ($Q3 >= 18 and $Q3 <= 24)}
). These conditions are carried forward and applied to each crosslist option. A common use case is nested demographic quotas, such as crossing age ranges and gender.
In the example below, the crosslist GENAGELIST is created by crossing the lists QP1 and AGELIST.
- QP1 is question-label shorthand, discussed in the previous example. QP1 is a single select question, and only one option will be present for each respondent.
- The options in AGELIST each have a condition referencing QP2. Ultimately, only one option's condition will be true, meaning only one option will be applicable for each respondent.
The optsfrom: GENAGELIST
tag does not require any locally defined conditions because the list options inherit conditions from both QP1 and AGELIST. Since QGENAGE is a type: quotas
variable, it will automatically "punch" the applicable option for each respondent based on the inherited conditions.
set list: GENLIST
1. Male
2. Female
3. Other gender identity
P1. What is your gender?
type: radio
optsfrom: GENLIST
P2. What is your age?
type: text
datatype: whole
range: 1-99
termif: ($QP2 < 18) {text: QP2 (Age: 17 or younger) }
set list: AGELIST
18. 18 - 24 {if ($QP2 >= 18 and $QP2 <= 24)}
25. 25 - 34 {if ($QP2 >= 25 and $QP2 <= 34)}
35. 35 - 44 {if ($QP2 >= 35 and $QP2 <= 44)}
45. 45 - 54 {if ($QP2 >= 45 and $QP2 <= 54)}
55. 55 - 64 {if ($QP2 >= 55 and $QP2 <= 64)}
65. 65+ {if $QP2 >= 65}
set list: GENAGELIST
crosslists: QP1,AGELIST
GENAGE. QUOTA |Gen-Age
type: quotas
optsfrom: GENAGELIST
Using decorator data
Additional data stored in lists with option data decorators can also be pulled into crosslists just like conditions. In the following example, a crosslist created from two lists with custom option data is referenced and displayed to the respondent.
Please scroll to see the full source code.
Referencing crosslist IDs in conditional logic
To reference a crosslist parent ID in a list call (e.g., optsfrom
), prefix the origin list name to the id
placeholder, separated by an underscore (e.g., '[LISTNAME_id]'). Prefixing clarifies list references and is necessary for the software to iterate across different lists.
In the example below, crosslist BRANDS_X_FAM uses the lists BRANDS and FAMILIAR to create its combined list.
set list: BRANDSTo reference the crosslist in conditional logic, such as on an
1. Bounty
2. Brawny
3. Scott
4. Seventh Generation
set list: FAMILIAR
1. Not at all familiar
2. Slightly familiar
3. Very familiar
4. Extremely familiar
set list: BRANDS_X_FAM
crosslists: BRANDS,FAMILIAR
optsfrom
tag, use 'BRANDS_id' and 'FAMILIAR_id' as placeholders. Enclose these references in square brackets, just like the standard [id] placeholder.
optsfrom: BRANDS_X_FAM {if anyChecked($Q1R[BRANDS_id],[FAMILIAR_id])}
Here:
- 'BRANDS_id' iterates through each ID from the BRANDS list, creating the row reference.
- 'FAMILIAR_id' iterates through each ID from the FAMILIAR list, becoming the answer option.
When using question-label shorthand, reference variable names instead of list names.
In the example below, crosslist BRANDS_PRODUCTS uses variables QL1BRANDS and QL1PRODUCTS to create its combined list.
set list: BRANDS_PRODUCTS
crosslists: QL1BRANDS,QL1PRODUCTS
Then, we could write the following:
rowsfrom: BRANDS_PRODUCTS {if anyChecked($QS14R[QL1BRANDS_id],[QL1PRODUCTS_id])}
Here:
- 'QL1BRANDS_id' pulls in any ID "punched" at QL1BRANDS, creating the row reference.
- 'QL1PRODUCTS_id' pulls in the IDs punched at QL1PRODUCTS, becoming the answer option.
Comments
0 comments
Please sign in to leave a comment.