------------------------------------------------------------------------------- help forcatplot-------------------------------------------------------------------------------

Plots of frequencies, fractions or percents of categorical data

catplot{bar|hbar|dot}catvar1[catvar2[catvar3]] [weight] [ifexp] [inrange] [,{fraction|fraction(varlist)|percent|percent(varlist)}missingsortdescendinggraph_options]

Description

catplotshows frequencies (or optionally fractions or percents) of the categories of one, two or three categorical variables. The first named variable is innermost on the display; that is, its categories vary fastest. The syntaxescatplot bar,catplot hbarandcatplot dotare specified to indicate use of graph bar, graph hbar and graph dot respectively. The choice is a matter of personal taste, although in general horizontal displays make it easier to identify names or labels of categories.

fweights,aweights andiweights may be specified.

RemarksThe default display with

barandhbaris graphically conservative, reflecting the view that height of bars and text indicating categories are the best ways of conveying information. If you wish also to have bars in different colours, specify the optionasyvars, which differentiates the categories of thefirstnamed variablecatvar1. If you wish also to stack bars of different colours, specify the further optionstack.The default display with

dotis similarly conservative. If you wish to have point symbols in different colours, specify the optionasyvars, which differentiates the categories of thefirstnamed variablecatvar1. If you wish also to use different point symbols, use the further optionmarker().

Options

fractionindicates that all frequencies should be shown as fractions (with sum 1) of the total frequency of all values being represented in the graph.

fraction(varlist)indicates that all frequencies should be shown as fractions (with sum 1) of the total frequency for each distinct category defined by the combinations ofvarlist. For example, given a variablesexwith two categories male and female, the fractions shown for male would have sum 1 and those for female would have sum 1.

percentindicates that all frequencies should be shown as percents (with sum 100) of the total frequency of all values being represented in the graph.

percent(varlist)indicates that all frequencies should be shown as percents (with sum 100) of the total frequency for each distinct category defined by the combinations ofvarlist. For example, given a variablesexwith two categories male and female, the percents shown for male would have sum 100 and those for female would have sum 100.Only one of these

fraction[()] andpercent[()] options may be specified.

missingspecifies that any missing values of any of the variables specified should also be included within their own categories.

sortspecifies that values shown should be sorted in each category (higher values at the bottom of each category). Sorting is applied to all variables shown.

descendingspecifies that sorted values should be shown in descending order (higher values at the top of each category).

graph_optionsrefers to options of graph bar, graph hbar or graph dot as appropriate.by()is one useful example.

Examples. sysuse auto

. catplot hbar rep78 foreign . catplot bar rep78, by(foreign) percent(foreign) . gen himpg = mpg > 25 . catplot hbar himpg rep78 foreign

. catplot hbar rep78 foreign, percent(foreign) bar(1, bcolor(blue)) blabel(bar, position(outside) format(%3.1f)) ylabel(none) yscale(r(0,60))

. catplot hbar rep78, sort . catplot hbar rep78, sort desc

AuthorNicholas J. Cox, University of Durham n.j.cox@durham.ac.uk

AcknowledgementsVince Wiggins provided very helpful comments. Fred Wolfe asked for sorting. David Schwappach provided feedback on limitations.

Also seeOn-line: help for histogram