pctab for Creating Percentage Tables


The pctab command, which is a part of the asdocx package, is a new tool in Stata that makes it easy to generate percentage tables from your data. With just one line of code, you can produce a neatly formatted table showing percentages of different variables broken down by a grouping variable. Please note that pctab is only available through the asdocx package.

The syntax for pctab is simple:

asdocx pctab varlist, by(groupby)

Where:

  • varlist is a list of variables for which you want percentages calculated. These will become the rows in your table.
  • by() specifies a single grouping variable. This will create a separate column for each unique value of the grouping variable.

For example, say we have survey data on industry, marital status, and education level. To generate a table showing the percentage of people married, never married, and with a college degree within each industry, our code would be:

  * Load example dataset
 sysuse nlsw88, clear
 
 * Create percentages of variables by industry
asdocx pctab married never_married college_grad, by(industry)
Table: Results
industry married_prc never_married_prc grade_prc
Ag/Forestry/Fisheries 0.971 0.427 0.67
Mining 0.069 0.427 0.163
Construction 1.179 0.855 1.201
Manufacturing 14.216 15.385 15.078
Transport/Comm/Utility 3.259 6.41 3.97
Wholesale/Retail Trade 14.355 13.248 13.87
Finance/Ins/Real Estate 9.293 5.556 8.464
Business/Repair Svc 4.022 4.274 3.674
Personal Services 3.329 7.265 3.742
Entertainment/Rec Svc 0.555 0.427 0.748
Professional Services 40.915 31.624 39.729
Public Administration 7.282 12.821 8.097
Notes:

pctab is designed to automate and simplify a common task that often requires more complex code. By specifying your variables and groups, it handles all the calculations and formatting behind the scenes. The resulting table makes it easy to see percentages and comparisons at a glance.

This new command eliminates the need for manual tabulations and formatting, allowing you to go from data to publication-ready tables with ease. I expect pctab will be a frequently used tool for Stata users who work with survey data and need to present descriptive statistics.

  See also


  • tabmany – Table of multiple coded answers
  • mrtab – One- and two-way tables of multiple responses
  • tabcount – tabulates frequencies for up to 7 variables
  • tab3way – Three way table of frequencies and percentages
  • missings – Various utilities for managing missing values
  • tabulate, tab1, tab2
  • crosstab – table of means and weighted by in cross tabulations
  • fre – One-way frequency tables

 

  Order asdocx


Yearly license of asdocx is available at $9.99. Its life-time license is available at $49.99. With the asdocx membership, you get :

  • Life-time license to use
  • All future updates
  • All premium templates / plugins.

 

Order asdocx