# st: RE: Graphing a categorical variable: simple bar chart.

 From "Nick Cox" To Subject st: RE: Graphing a categorical variable: simple bar chart. Date Mon, 17 Nov 2003 18:07:17 -0000

```Ernest Berkhout has already answered
"histogram", and that's probably the best

But I don't think it's the whole story.
Here I repeat parts of a posting from 21 February.

I work a lot with students and others who want bar
charts of categorical data, for example, of counts
of categories from one-way, two-way or even three-way
tables from questionnaires and other survey data.
In addition, many of these users want to tell me
for some reason that it's very easy in Excel, so
I really want to be able to say to them that it's
also very easy in Stata.

How does Stata size up on this task?

1. -histogram- is optimised for histograms,
naturally. It can be used for this purpose by
invoking options like

, discrete xla(, valuelabel ang(45)) gap(50)

for a one-way table or

, discrete xla(, valuelabel ang(45)) gap(50)
by(myvar, rows(1))

for a two-way table. Typing this -- or issuing
the equivalent through a dialog -- is a
little more complicated than some Stata beginners
might expect for this task. In any case,
some problems then frequently arise:

a. it doesn't take much for value labels to become
unreadable or to require what I call giraffe graphics,
in which the graphic necessitates a great deal of neck
movement. (That's why I have "ang(45)" in the examples
above.)

b. The number of cells you can show easily and effectively
appears to be ~20, given that you will want value
labels shown to indicate the categories. Any long
value labels make this problem worse.

c. Representing a 3-way table seems impossible, except by
producing and then combining separate histograms.

2. -graph hbar- etc. is good _if_ the
frequencies come predefined as a variable, because
then you can just sum the frequencies. But
if you want Stata to do the counting for you,
this seems to require you to set up something
to count. In particular,

. graph hbar (count) rep78

doesn't give you the frequencies of the
categories of -rep78-. Roughly, we want -graph-
here to -contract-, not -collapse-.

The way to do it is to calculate something in

. gen freq = 1
. graph hbar (count) freq, over(rep78)

but arguably we shouldn't have to do that.
And as for percents, catching missings,
and working with -if- and -in-: it
really needs a program.

One program in this area is -catplot-
from SSC. What it actually does can be seen by reading the help

. ssc type catplot.hlp

and then if interested you can install

. ssc inst catplot

However, there is no dialog for this program.
Wendy or anybody else should feel free
to write the corresponding dialog program.

Nick
n.j.cox@durham.ac.uk

wendy olsen

> Are we daft or just uninformed?  How do we use the Menus to
> make a simple univariate bar chart of %s?
>
> We can't make a chart of counts either using Graphics /
> Easygraphs / Bar / and put in one variable in the dialog box.
>
> If someone could send us the equivalent syntax for a simple bar
> chart we';ll be grateful, but for teaching purposes we need a Menu
> option.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```