Create New Variables - Pick Any with All Combinations
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.).
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);
}