The autocode
tag automatically sets an answer for a closed-ended question or table based on a previous question's answer and skips the respondent over the question.
4. What are the main reasons you decided to apply for your credit card?
type: checkbox
randomize: y
1. Annual fee is a good value for the rewards and benefits offered
2. Offered valuable rewards
3. Offered benefits I wanted (e.g., airport lounge access, hotel upgrades, cell phone protection)
4. Had a high credit limit
5. Low interest rate
6. BRAND is a well-respected and a premium issuer
7. My friends/family recommended this card
97. Other {autoother: y} {anchor: y}
4A. And what would you say is the PRIMARY reason you decided to apply for your credit card?
type: radio
optsfrom: Q4
autocode: $Q4 {if countChecked($Q4)==1}
Details
-
Multiple
autocode
tags may be applied to a question. - The
autocode
tag accepts both static values (e.g., '1') and dynamic values based on the respondent's previous answer as input. Dynamic values can be simple (e.g., '$Q4') or more complex (e.g.,listWhich(VENDORS; anyChecked($Q14R[id],4); [id])
). - The options for
autocode
can be provided as an inline list or referenced using a listcall (e.g.,optsfrom
). -
autocode
automatically manages the conditional display of the question, so skip logic with theshowif
tag is not needed. If skip logic is applied, the question will not be autocoded for respondents who do not see it.
Tip! The autocode
tag is not intended for use on complex questions/tables. Create a set value
widget instead.
Additional examples
Autocoding a static value
In the example below, if '0' is entered in Q1, Q2's option 1 ("I was alone") is automatically selected, and the question is skipped. The condition on option 1 ensures that "I was alone" is not displayed for respondents who answer Q2. This way, the client will have data for all respondents, even though some may skip the question.
Using multiple 'autocode' tags
autocode
can be applied multiple times on a question if different options need to be set based on varying conditions. In the example below, if the respondent answered "None of the above" in Q5, there are no relevant options to display at Q6. Therefore, we can use autocode
to store the answer '991' (None of the above) and skip it. Similarly, if the respondent selected only one meal in Q5, it makes sense to code that same option as the "favorite" and skip Q6 for that respondent.
Autocoding a static value from a table with 'rowpunchsummary'
You can aggregate a table's results with the rowpunchsummary
tag and use the information collected to autocode a follow-up question.
In the example below, we leverage the rowpunchsummary
tag to summarize the brands selected as "tried" at Q7. The autocode
tag is then applied to Q8, setting the answer to '99. I have not tried any' if no brands are "punched" in the summary variable Q7YES.
Autocoding a dynamic value from a table
Using the same example from above, imagine the client requests to modify the logic so that respondents who have only tried one brand at Q7 skip over Q8, and that single brand is automatically coded as their favorite. We can instead use the listWhich
function to dynamically determine and set the favorite brand.
In the example below, the listWhich
function checks each row of the BRANDLIST at Q7A for "tried" (option 1 or Q7AYES). If only one brand satisfies this condition, listWhich
will return that brand's ID. This brand can then be autocoded as the answer for Q8A, and Q8A will be skipped for these respondents.
In the example below, we've kept the same BRANDLIST and Q7A, but we have a new Q8A to address the client's needs.
In the example above, we could also replace the listWhich
syntax with '$Q7AYES', for example, autocode: $Q7AYES {if countChecked($Q7AYES)==1}
.
Comments
0 comments
Please sign in to leave a comment.