Tables - Tables Showing Don't Knows

From Q
Jump to navigation Jump to search

This tool looks for Don't Know responses in the selected questionsvariable sets, and generates a new questionvariable set and table for each which shows the respondents that selected a Don't Know option in that question.

Standard wordings for Don't Know responses are checked (see the list below). If your survey uses different labeling for Don't Know (for example, if the survey is not written in English) you can elect to enter your own custom text labels to include in the check.



Technical details

Phrases that are identified as Don't Know type responses are ones that contain one or more of:

  • dk
  • dont know
  • don't know
  • don t know
  • unsure
  • not sure
  • do not know
  • no idea
  • not applicable

The matching of these is not case sensitive.

Additionally, where a label is, in its entirety, NA or na, it is treated as a Don't Know.

If one of the selected questionsvariable sets appears to have more than one Don't Know category, then it will be added to a separate folder. These should be checked carefully, because it is unusual to have more than one option for a respondent to indicate a Don't Know response to a survey question.

How to apply this QScript

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Click on the QScript when it appears in the QScripts and Rules section of the search results.


  • Select Automate > Browse Online Library.
  • Select this QScript from the list.

Customizing the QScript

This QScript is written in JavaScript and can be customized by copying and modifying the JavaScript.

Customizing QScripts in Q4.11 and more recent versions

  • Start typing the name of the QScript into the Search features and data box in the top right of the Q window.
  • Hover your mouse over the QScript when it appears in the QScripts and Rules section of the search results.
  • Press Edit a Copy (bottom-left corner of the preview).
  • Modify the JavaScript (see QScripts for more detail on this).
  • Either:
    • Run the QScript, by pressing the blue triangle button.
    • Save the QScript and run it at a later time, using Automate > Run QScript (Macro) from File.

Customizing QScripts in older versions

  • Copy the JavaScript shown on this page.
  • Create a new text file, giving it a file extension of .QScript. See here for more information about how to do this.
  • Modify the JavaScript (see QScripts for more detail on this).
  • Run the file using Automate > Run QScript (Macro) from File.


includeWeb('QScript Utility Functions');
includeWeb('QScript Questionnaire Functions');
includeWeb('QScript Selection Functions');
includeWeb('QScript Functions to Generate Outputs');
includeWeb('QScript Value Attributes Functions');
includeWeb('JavaScript Text Analysis Functions');
function main() {
    let extra_dk_strings = promptForDKLabels();
    let selected_questions;
    let allowed_types = ["Pick One", "Pick One - Multi", "Number", "Number - Multi"]; 
    if (inDisplayr()) {
        // In Displayr, get explicitly selected questions, or if none get
        // all questions in selected data sets.
        let user_selections = getAllUserSelections();
        selected_questions = user_selections.selected_questions;
        // Enable user to select whole data sets
        if (selected_questions.length == 0) {
            let selected_data_sets = user_selections.selected_data_sets;
            if (selected_data_sets.length > 0) {
                selected_data_sets.forEach(function (data_set) {
                    selected_questions = selected_questions.concat(data_set.questions);
        if (selected_questions.length == 0) {
            log("Please select one or more variable sets or an entire data set.");
        selected_questions = selected_questions.filter(x => allowed_types.indexOf(x.questionType) > -1);
        selected_questions = getDKQuestionsFromSelection(selected_questions, extra_dk_strings);
        if (selected_questions.length == 0) {
            log("None of the selected variable sets contained Don't Know categories.")
    } else {
        // In Q the best selection mode for the user is via menus.
        let relevant_questions = getDKQuestionsWithUserEnteredLabels(
        if (relevant_questions.length == 0) {
            log("No appropriate questions found.");
            return false;

        selected_questions = selectManyQuestions(
            "Select the questions to display Don't Know responses for:", 
        if (selected_questions.length == 0) {
           log(correctTerminology("No questions selected."));
            return false;
    // Questions with more than 1 don't-know should be inspected by the user
    let questions_to_check = []; 
    let easy_questions = [];
    selected_questions.forEach(function (q) {
        let new_question_and_count = constructQuestionToCountDKResponses(q, extra_dk_strings);
        let new_q = new_question_and_count.question;
        if (new_question_and_count.dk_count > 1)
    let new_group_name = "Don't Know Responses";
    let new_group = generateGroupOfSummaryTables(new_group_name, easy_questions);
    let tables = [];
    recursiveGetAllTablesInGroup(new_group, tables);

    if (questions_to_check.length > 0) {
        log(correctTerminology("Some questions appear to have more than one Don't Know category and should be checked."));
        let check_group_name = inDisplayr() ? "Multiple Don't Know Labels Detected" : "Questions to check";
        let check_group = generateSubgroupOfSummaryTables(
        recursiveGetAllTablesInGroup(check_group, tables);
    tables.forEach(function (table) {
        if (table.type == "Table")
            table.cellStatistics = ['%', 'n', 'Base n', 'Missing n'];

    if (fileFormatVersion() > 8.65)[new_group.subItems[0]]);
    return true;

function constructQuestionToCountDKResponses(q, extra_dk_strings) {
        let value_attributes = q.valueAttributes;
        let dk_count = 0;
        let dk_values = [];
        let new_q = q.duplicate(
       + " - Don't Know"
        new_q.questionType = "Pick Any";
        q.uniqueValues.forEach(function (v) {
            let cur_label = value_attributes.getLabel(v); 
            if (isDontKnow(cur_label) || containsSubstring(cur_label, extra_dk_strings) ) {
        let new_value_attributes = new_q.valueAttributes;
        new_q.uniqueValues.forEach(function (v) {
            // If the DK value was already set as missing then set it as not missing
            if (dk_values.indexOf(v) > -1 && new_value_attributes.getIsMissingData(v)) {
                setIsMissingDataForVariablesInQuestion(new_q, v, false);
            setCountThisValueForVariablesInQuestion(new_q, v, dk_values.indexOf(v) > -1);
        return {question: new_q, dk_count: dk_count}

Prior to the 15th of December, 2015, this page was known as Create New Variables - Creating Tables Showing Don't Knows

See also