Coded variables are hidden questions with a built-in selection or calculation process for single select, multi-select, and numeric input questions. They are created using the type: coded single select
, type: coded multiple select
, or type: coded
number
tags, respectively.
1. Do you have any of the following food allergies?
instruct: Select all that apply.
type: checkbox
randomize: y
1. Tree nuts (almond, cashews, walnuts)
2. Peanuts
3. Milk / Dairy
4. Eggs
5. Wheat and/or Gluten
6. Fish
7. Soy
99. I don't have food allergies {exclusive: y}
FISHALLERGY. VAR | Allergic to Fish or NOT
type: coded single select
1. Yes, allergic to fish {if anyChecked($Q1,6)}
2. No, NOT allergic to fish {if noneChecked($Q1,6)}
Details
- Coded single select and coded multiple select variables have
selectby: condition
built into them. Unless theselectby
method is modified, each option in the variable requires a condition. - To use a different
selectby
method with a coded single select or coded multiple select variable, include aselectby
tag specifying another input, e.g.,selectby: weights
. - The
cvalue
tag should be included on coded number variables to specify logic or mathematical equations for calculating the value stored by the variable. -
Quotas and click balance quotas (CBQs) can be created from coded variables by including the
quotas: y
andclick balance quotas: y
tags, respectively.
Commonly used tags
Tag | Description | Use with |
(alias |
Set to 'y' to create a "click balance quota" (CBQ) from a question. CBQs are based on all incoming traffic, instead of completes like a regular quota. | coded single select and coded multiple select |
cvalue |
Calculates and sets a value for a coded number variable or when a single or multiple select coded variable uses
|
coded number variables, or when using selectby: calculate with closed end coded variables |
maxgroups |
Sets a maximum number of options or groups that a respondent may be assigned to if they meet the condition criteria. | coded multiple select variables |
quotas |
Set to 'y' to create a quota variable from a question based on the number of completes. | coded single select and coded multiple select |
selectby |
Specifies how to assign respondents to a group when they may qualify for more than one. Common The |
all coded variable types |
Additional examples
For the purposes of this article, we will use an extended example to illustrate various ways in which coded variables can be created. The examples that follow will reference the survey code below. Each section will highlight a specific part to demonstrate how the coded variable is created.
The following set of questions asks respondents for their familiarity with and usage of various grocery stores, examining whether they tend to use "supermarkets" or "club/warehouse" grocers more frequently.
setlist: STORES randomize: y
1. Market Basket
2. Price Chopper
3. Price Rite
4. ShopRite
5. Tops
6. Weis Markets
7. Wegmans
8. BJ's Wholesale Club
9. Costco
10. Sam's Club
1. Which of the following stores have you ever heard of?
type: checkbox
optsfrom: STORES
2. Which of the following stores have you shopped at in the last year? type: checkbox optsfrom: STORES {if anyChecked($Q1,[id])} 99. None of the above {exclusive: y}
HEARD. Stores heard of but never shopped type: coded multiple select optsfrom: STORES { if anyChecked($Q1,[id]) and noneChecked($Q2,[id]) }
3. What percent of your shopping is done at each of the following stores? type: integer table postfix: % range: 0-100 rowsfrom: STORES { if anyChecked($Q2,[id]) } showcolumntotal: <b>Total</b> {total: 100} {message: Please ensure you responses add up to 100%.}
GT10. Stores where at least 10% of shopping done type: coded multiple select optsfrom: STORES {if $Q3R[id]>=10}
PRIMARY. Store where majority of shopping done type: coded single select selectby: weight optsfrom: STORES {weight: $Q3R[id]}
TOP2. Top 2 Stores where shopping done type: coded multiple select maxgroups: 2 selectby: weight, counts optsfrom: STORES {weight: $Q3R[id]}
CLUB. Is primary store club or grocery? type: coded single select 1. Supermarket {if anyChecked($QPRIMARY,1..7)} 2. Club / Warehouse {if anyChecked($QPRIMARY,8..10)}
CLUB1. Is primary store club or grocery?
desc: Same as QCLUB but using calculate and cvalue type: coded single select selectby: calculate cvalue: if ($QPRIMARY<8) {1} else {2} 1. Supermarket 2. Club / Warehouse
TOTAL_SPEND_GROCERY. Total Spend at Grocery Stores type: coded number cvalue: listSum(STORES [1..7]; $Q3R[id])
TOTAL_SPEND_CLUB. Total Spend at Club Stores type: coded number cvalue: listSum(STORES [8..10]; $Q3R[id])
Applying conditions on a list call
Condition decorators can be applied to a listcall to specify which options should be included in a coded single select or multiple select variable. In this example, QHEARD stores all options that were selected in Q1 (stores they'd heard of) but didn't select in Q2 (hadn't shopped at).
HEARD. Stores heard of but never shopped
type: coded multiple select
optsfrom: STORES { if anyChecked($Q1,[id]) and noneChecked($Q2,[id]) }
Overriding default selectby inputs
To use a different selection method than 'condition' for coded single select or multiple select variables, add the selectby
tag to your variable with a different input. Specify multiple selection methods by separating the inputs with a comma. For QTOP2, if there is a tie in the weight for two or more stores, the store with the lowest counts will be selected.
PRIMARY. Store where majority of shopping done
type: coded single select
selectby: weight
optsfrom: STORES { weight: $Q3R[id] }
TOP2. Top 2 Stores where shopping done
type: coded multiple select
maxgroups: 2
selectby: weight, counts
optsfrom: STORES { weight: $Q3R[id] }
When using selectby: calculate
, include the cvalue
tag to specify how values are calculated. In the STORES list, all Supermarkets have an option ID less than 8, while Club/Warehouse stores have options IDs of 8 and above.
CLUB1. Is primary store club or grocery?
desc: Same as QCLUB but using calculate and cvalue
type: coded single select
selectby: calculate
cvalue: if ($QPRIMARY<8) {1} else {2}
1. Supermarket
2. Club / Warehouse
Calculating coded number variables
To define a coded number variable, include the cvalue
tag with a mathematical or logical expression.
TOTAL_SPEND_GROCERY. Total Spend at Grocery Stores type: coded number cvalue: $Q3R1 + $Q3R2 + $Q3R3 + $Q3R4 + $Q3R5 + $Q3R6 + $Q3R7
Comments
0 comments
Please sign in to leave a comment.