Scripting > mrScriptMetadata User's Guide > mrScriptMetadata reference > Field definitions > Boolean
 
Boolean
The boolean type defines a question that requires a True or False value as the response.
Syntax
For clarity, each item is shown on a separate line, and optional items are indented. See also Syntax conventions.
field_name [ "field_label" ]
    [ [ <properties> ] ]
    [ <styles and templates> ]
boolean [ <categories> ]
    [ <codes> ]
    [ expression ("expression_text") ]
    [ ( initialanswer | defaultanswer ) ( true | false ) ]
    [ <axis> ]
    [ <usage-type> ]
    [ <helperfields> ]
    [ nocasedata ]
    [ unversioned ]
Parameters
For <axis>, <usage-type>, <helperfields>, nocasedata, and unversioned, see Common parameters.
<categories>
You can use the optional categories list to specify that the question will be presented as a single-response categorical question. If a category is selected, the value of the response will be the factor value assigned to that category by the factor keyword. Therefore, all categories should be assigned a factor value. In the following example, the value of Children will be true or false, depending on which of the two categories is selected:
Children "Do you have any children?" boolean
  {
    Yes factor(True),
    No factor(False)
  };
For further information about defining a category list, see Categorical.
<codes>
The optional codes list is used to define special responses for the question. A code list is defined in the same way as a category list and is typically used to include Don't Know, No Answer, or Refused to Answer responses, which are identified by the DK, NA and REF keywords respectively. For example, the following defines a boolean question called AttendMovies that has a No Answer response. Special responses are automatically marked as exclusive, meaning that it cannot be combined with any other answers. Only True, False, or No Answer are acceptable responses:
AttendMovies "Do you go to the movies?" boolean codes (
  {
    NoAnswer "No answer" NA
  } );
When using the DK, REF or NA keywords, you can use a hyphen (-) as the category name to specify that the category name should be the same as the keyword.
expression
The optional expression keyword is used to create a variable using a formula defined in expression_text. Generally you use this feature to create a derived variable that is based on one or more other variables. For example, the following creates a boolean derived variable that could be used as a filter for young men. The expression uses the intersection (*) operator to test whether the respondent's age stored in the Age variable is in any of the young age groups.
YoungMen "Young men filter" boolean
    expression ("Gender = {Male} And Age * {Y11_16, Y17-20, Y21_24, Y25_34}");
expression_text must be an expression that is supported by the UNICOM Intelligence Data Model and can optionally include functions from the UNICOM Intelligence Function Library. Double quotation marks (") must be escaped using a second double quotation mark (for example, ""yyyy""). Make sure that you check your syntax and spelling carefully, because the expression is stored without being validated. See Expression evaluation for more information.
initialanswer and defaultanswer
You can optionally specify either an initial answer or a default answer to the question. An initial answer can be seen by the respondent, whereas a default answer can not be seen. If either type of answer is defined, the respondent does not need to answer the question. For example:
Subscribe "Would you like to subscribe to our newsletter?" boolean
  { Yes "Yes please" factor(True),
    No "No thanks" factor(False)
  }
  defaultanswer(false);
If a default answer is not accepted when you run the interview script, in other words, the message “Missing Answer(s)” is displayed, see mrScriptMetadata FAQs.
Remarks
For more information about writing Boolean questions in interview scripts, see Questions with Yes/No responses.
Example
The following defines a boolean question called Sample with the question text Would you like a sample of our product?, for which True, False, or Don't Know are valid responses:
Sample "Would you like a sample of our product?" boolean
{
Yes "Yes I would" factor(True),
No "No thanks" factor(False)
}
codes (
{
- "Not sure at the moment" DK
} );
See
Field definitions