Create New Variables - Pick Any with All Combinations

From Q
Jump to navigation Jump to search

Converts one or more variables into binary variables. For example, if you select an age variable containing six categories, the result will be a new question containing six binary variables, each corresponding to one of the age categories. If you select age and gender, you would create 12 variables (e.g., “Male 18 to 24”, “Female 18 to 24”, “Male 25 to 34”, etc.).

var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};

// The require function
function __webpack_require__(moduleId) {

// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);

// Return the exports of the module
return module.exports;

}

// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
includeWeb("QScript Selection Functions");
includeWeb("QScript Utility Functions");

function createPickAnyWithAllCombinations(selected_variables) {
    if (selected_variables.length === 0) {
        alert('Please select at least one non-text variable.');
        return;
    }

    const data_file = selected_variables[0].question.dataFile;
    const new_variable_count = data_file.calculateVariableCountForPickAnyWithAllCombinations(selected_variables);

    if (new_variable_count < 0) {
        alert('The number of new variables exceeds the maximum limit of integer. Please select fewer variables.');
        return;
    }

    let threshold = 0;
    if (new_variable_count > 1000) {
        threshold = 1000;
    }
    else if (new_variable_count > 500) {
        threshold = 500;
    }
    else if (new_variable_count > 25) {
        threshold = 25;
    }

    if (threshold > 0) {
        if (!confirm(`More than ${threshold} variables will be constructed. Are you sure you want to continue?`)) {
            return;
        }
    }

    const new_variable_set = data_file.createPickAnyWithAllCombinations(selected_variables);
    if (!new_variable_set) {
        return;
    }
    return new_variable_set;
}

if (requireDataFile()) {
    const selected_variables = getAllUserSelections().selected_variables.filter(v => v.variableType !== 'Text');
    createPickAnyWithAllCombinations(selected_variables);
}

See also

Insert Ready-Made Formula(s) Menu