Thanks as ever to Kit Baum. a new version of catplot is available on SSC. If you're interested in plotting categorical data and have never heard of catplot you should
GOTO to COMEFROM
and skip or at most skim this preamble. If you know about catplot and want to know more about why it has been revised, the full story is longer than I want to tell, but here's a synopsis.
Stata has supported bar charts from early days but with a bias towards plotting variables you have already, or summaries of them like means. Plotting bar (or dot) charts for categorical data is a two-step problem, trivial though the two steps may seem: calculate frequencies, proportions, or percents as new variables; and then draw your charts. But such charts were not so well supported.
In the 1990s various user-written (community-contributed as we now say) commands were posted as extensions to fill the gap. In 2003, Stata's official graphics was completely revamped in Stata 8, yet charts for categorical data were still not well supported. But as in some of those 1990s extras, it was evident that something like
and then say
would get you there in two steps in terms of a chart of frequencies. Proportions and percents are harder, although the code looks all too obvious once you have thought it out. There is no fun in doing that the second time, let alone repeatedly, so catplot was born as a wrapper and posted on SSC early in 2003. The syntax was a bit awkward, so I acted quickly and posted a revised version in 2010. The syntax was still a bit awkward so I am again acting quickly to post a revised version 14 years later, prompted partly by a recent kind comment from a Stata friend that the command remains useful.
Meanwhile, StataCorp also acted quickly and added graph bar (count) and graph bar (percent) and their equivalents for hbar and dot in 2014 in the life of Stata 13. I have not completely mastered either as new syntax, given that I already knew how to do it with other commands. And as catplot seems to remain popular, whether the reasons for that are good or not so good, I thought that a re-issue was overdue.
COMEFROM from GOTO
What's new in this release?
catplot remains a wrapper for official graph commands, but the syntax is closer to that of official Stata.
The help file is much extended with more examples.
I've added some discouragement from adding asyvars or asyvars stack which in my prejudiced view are often steps in a poor direction.
Here's a taster in terms of examples of its use. I use stcolor in Stata 18. If you're working with a previous version or prefer a different scheme, some tweaks may seem desirable, as well as a different scheme specification.
(graph not shown here, but similar to previous in shape)
GOTO to COMEFROM
and skip or at most skim this preamble. If you know about catplot and want to know more about why it has been revised, the full story is longer than I want to tell, but here's a synopsis.
Stata has supported bar charts from early days but with a bias towards plotting variables you have already, or summaries of them like means. Plotting bar (or dot) charts for categorical data is a two-step problem, trivial though the two steps may seem: calculate frequencies, proportions, or percents as new variables; and then draw your charts. But such charts were not so well supported.
In the 1990s various user-written (community-contributed as we now say) commands were posted as extensions to fill the gap. In 2003, Stata's official graphics was completely revamped in Stata 8, yet charts for categorical data were still not well supported. But as in some of those 1990s extras, it was evident that something like
Code:
gen freq = 1
Code:
graph bar (sum) freq, over(foo) over(bar)
Meanwhile, StataCorp also acted quickly and added graph bar (count) and graph bar (percent) and their equivalents for hbar and dot in 2014 in the life of Stata 13. I have not completely mastered either as new syntax, given that I already knew how to do it with other commands. And as catplot seems to remain popular, whether the reasons for that are good or not so good, I thought that a re-issue was overdue.
COMEFROM from GOTO
What's new in this release?
catplot remains a wrapper for official graph commands, but the syntax is closer to that of official Stata.
The help file is much extended with more examples.
I've added some discouragement from adding asyvars or asyvars stack which in my prejudiced view are often steps in a poor direction.
Here's a taster in terms of examples of its use. I use stcolor in Stata 18. If you're working with a previous version or prefer a different scheme, some tweaks may seem desirable, as well as a different scheme specification.
Code:
. set scheme stcolor * Read in data . sysuse auto, clear * Horizontal bar chart showing category frequencies . catplot, over(rep78) name(G1, replace)
Code:
* Horizontal bar chart showing category percents . catplot, over(rep78) percent name(G2, replace)
Code:
* Given foreign or domestic, what is percent breakdown of repair record? . catplot, over(rep78) over(foreign) percent(foreign) name(G3, replace)
Code:
* Given repair record, what is percent breakdown of foreign or domestic? . catplot, over(foreign) over(rep78) percent(rep78) name(G4, replace)
Code:
* And show the percents as numeric text? (You may need to add some space) . catplot, over(foreign) over(rep78) percent(rep78) blabel(bar, format(%02.0f)) ysc(r(0 105)) name(G5, replace)
Code:
* Show that as a side-by-side display - and add an axis title too . catplot, by(foreign, l1title(Repair record 1978)) over(rep78) percent(rep78) blabel(bar, format(%02.0f)) ysc(r(0 105)) name(G6, replace)
Comment