This article describes how to create a frequency table in Q. A frequency table shows the number of times each unique value appears in one or more variables. They are commonly used for reporting (e.g., providing the data to appear in charts) and for data cleaning.
For example:
Requirements
A category variable that you want to create a table showing counts and percentages.
Method
- From the Blue drop down menu, select the variable you want to display in a table
- From the Brown drop down menu, ensure that SUMMARY is selected.
- Right-click the cell in the upper-left corner and select Statistics - Cells > n
Creating a Frequency Table from code
The following JavaScript code adds a new table to the Report containing a SUMMARY of a Pick One question.
// Working on Phone.sav, this creates a new frequency table of Age.
var t = project.report.appendTable();
t.primary = project.dataFiles[0].getQuestionByName('Age');
t.secondary = "SUMMARY";
Note that:
- project.report.appendTable() tells Q to append a table to the project’s report tree.
- var t = tells Q to refer to the table that has been created as t in the rest in the script.
- The second and third line of the code tell Q which questions to select in the blue and brown drop-downs respectively. In this example, we have created a frequency table by selecting SUMMARY in the brown drop-down. To instead create a crosstab of age by gender:
var t = project.report.appendTable();
t.primary = project.dataFiles[0].getQuestionByName('Age');
t.secondary = project.dataFiles[0].getQuestionByName('Gender');
Next
How to Understand Frequency Tables (Summaries of Pick One and Pick Any Questions)