In the data cleaning and checking process you might want to review variable sets that have particular categories as responses to see if you want to include or not include them. The code below checks each non-Text variable set for a specific category label and makes a table of the variable set for you to review.
Technical details
Reads through all the variable sets in a data file and identifies any containing a response option of Don’t know or DON’T KNOW and creates a frequency table of each. If using Q, a useful data file to test this on is C:\Program Files\Q\Examples\Phone.sav (this may be located on a different place on your computer depending upon how Q was installed).
When reviewing this example, please keep in mind that some tables may not show a Don’t know response because it has already been set as missing in the raw data.
Method
You will use the code below in a custom QScript.
log("Creating tables of all questions that contain DK"); var data_file = project.dataFiles[0]; var report = project.report; var dks = report.appendGroup(); dks.name = "Tables of questions containing Don't Know responses"; var n_quest = data_file.questions.length; for (var i=0; i<n_quest; i++){//looping through the project //getting each question var q = data_file.questions[i]; if (q.questionType != "Text" && q.questionType != "Text - Multi") { var unique_vals = q.uniqueValues var val_attr = q.valueAttributes; for (var counter=0; counter < unique_vals.length; counter++) { var val = unique_vals[counter]; var lab = val_attr.getLabel(val); if (lab == "Don't know" || lab == "DON'T KNOW") { //Add a summary table. var table = dks.appendTable(); table.primary = q; table.secondary = "SUMMARY"; table.cellStatistics = ["%", "n"]; } } } }
See also
- QScript for an explanation of how to run this code.
- QScript Examples Library for other examples.
- QScript Reference for technical information.
- 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.
- JavaScript Variables for detail on how to create new variables.