Quality Assurance - Audit This Project
Jump to navigation
Jump to search
Q Technical Reference
Q Technical Reference
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library
This QScript reviews missing data, recoding of values and changes to labels in a project.
Example
AUDIT REPORT Source Values and Source Labels counted in Pick Any questions Q14 to q23. Social motives Q14: To be appreciated(2); Q14 to q23. Social motives Q15: To be dependent(2); Q14 to q23. Social motives Q16: To be successful(2); Q14 to q23. Social motives Q17: To have no friends(2); Q14 to q23. Social motives Q18: To be open to new experiences(2); Q14 to q23. Social motives Q19: A job offering independence and creativity(2); Q14 to q23. Social motives Q20: To feel unfit and out of shape(2); Q14 to q23. Social motives Q21: Doing work that is meaningful(2); Q14 to q23. Social motives Q22: To be powerless(2); Q14 to q23. Social motives Q23: Being recognised for your work(2); Source values set as Missing Data Q6_A_2: Don t Know(1); Q6_B_2: Don t Know(1); Q6_C_2: Don t Know(1); Q6_D_2: Don t Know(1); Q6_E_2: Don t Know(1); Q6_F_2: Don t Know(1); Values recoded as NaN but not set as Missing Data Q3: 65+(10); Value Labels changed from their source Label Q3: '65 or more' => '65+'; Q14: 'To be admired' => '1st'; 'To be appreciated' => '2nd'; Q15: 'To be selfish' => '1st'; 'To be dependent' => '2nd'; Q16: 'To be in charge' => '1st'; 'To be successful' => '2nd'; Labels of Variables changed from their source Label Q1_F_c: 'Q1. Fragments - Coke - Coded: Q1. Fragments - Coke' => 'Coke' Q1_E_c1: 'Q1. Fragments - Coke - Coded: Q1. Fragments - Diet Coke' => 'Diet Coke' Q1_D_c: 'Q1. Fragments - Coke - Coded: Q1. Fragments - Coke Zero' => 'Coke Zero' Q1_C_c1: 'Q1. Fragments - Coke - Coded: Q1. Fragments - Pepsi' => 'Pepsi' Q1_A_c: 'Q1. Fragments - Coke - Coded: Q1. Fragments - Diet Pepsi' => 'Diet Pepsi' Q1_B_c1: 'Q1. Fragments - Coke - Coded: Q1. Fragments - Pepsi Max' => 'Pepsi Max' Q3_3: 'Q3. Age' => 'Q3. Age in years'
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.
OR
- 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
JavaScript
//checking the variable type information
var data_file = project.dataFiles[0];
var variables = data_file.variables; //gets all variables
var n_variables = variables.length;
var recoding_report = "Recoding\r\n";
var multiple_response_report = "Source Values and Source Labels counted in Pick Any questions\r\n";
var missing_values_report = "Source values set as Missing Data\r\n";
var NaN_report = "Values recoded as NaN but not set as Missing Data\r\n";
var changed_value_label_report = "Value Labels changed from their source Label\r\n";
var changed_variable_label_report = "Labels of Variables changed from their source Label\r\n";
var invalid_variables_report = "";
for (var v = 0; v < n_variables; v++){
var variable = variables[v];
if (variable.question.isValid) {
if (variable.variableType != "Text"){
var variable_name = variable.name;
var values = variable.uniqueValues;
var n_values = values.length;
var changed_values = "";
var mr = variable.question.questionType == "Pick Any";
var counted_values = "";
var missing_data = "";
var NaNs = "";
var labels = "";
var attributes = variable.valueAttributes;
for (var i = 0; i < n_values; i++){
var source_value = values[i];
var value = attributes.getValue(source_value);
var label = attributes.getLabel(source_value);
var source_label = attributes.getSourceLabel(source_value);
if (source_value != value)
changed_values += source_value.toString() + " => " + value.toString() + "; ";
if (mr && attributes.getCountThisValue(source_value))
counted_values += source_label + "(" + source_value.toString() + "); ";
if (attributes.getIsMissingData(source_value))
missing_data += label + "(" + source_value.toString() + "); ";
else if (isNaN(value))
NaNs += label + "(" + source_value.toString() + "); ";
if (source_label != label)
labels += "'"+source_label + "'" + " => " + "'" + label+ "'" +"; ";
}
}
if (changed_values != "") recoding_report += variable_name + ": " + changed_values + "\r\n";
if (mr) multiple_response_report += variable.question.name + " " + variable_name + ": " + counted_values + "\r\n";
if (missing_data != "") missing_values_report += variable_name + ": " + missing_data + "\r\n";
if (NaNs != "") NaN_report += variable_name + ": " + NaNs + "\r\n";
if (labels != "") changed_value_label_report += variable_name + ": " + labels + "\r\n";
if (variable.label != variable.sourceLabel) changed_variable_label_report += variable_name + ": " + "'" + variable.sourceLabel+ "'" +" => " + "'" +variable.label + "'" + "\r\n";
} else {
invalid_variables_report = invalid_variables_report + (invalid_variables_report.length == 0 ? "Invalid Variables\r\n" : "\r\n") + variable.name;
}
}
log("AUDIT REPORT\r\n" + multiple_response_report + "\r\n" + missing_values_report + "\r\n" + NaN_report + "\r\n" + changed_value_label_report + "\r\n" + changed_variable_label_report + "\r\n" + invalid_variables_report);
See also
- QScript for more general information about QScripts.
- QScript Examples Library for other examples.
- Online JavaScript Libraries for the libraries of functions that can be used when writing QScripts.
- QScript Reference for information about how QScript can manipulate the different elements of a project.
- JavaScript for information about the JavaScript programming language.
- Table JavaScript and Plot JavaScript for tools for using JavaScript to modify the appearance of tables and charts.
Q Technical Reference
Q Technical Reference
Q Technical Reference
Q Technical Reference
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Setting Up Data > Creating New Variables
Q Technical Reference > Updating and Automation > Automation Online Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library
Q Technical Reference > Updating and Automation > JavaScript > QScript > QScript Examples Library > QScript Online Library