Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: bar graphs


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: bar graphs
Date   Wed, 8 Jan 2003 12:53:29 -0000

Rob Bossarte

> I am trying to generate a bar graph with the cumulative
> percent of a variable along the y-axis instead of either
> simple counts or means. I can't seem to find anything in
> the STATA graphics guide.

Lee Sieswerda

> Try typing:
> findit cumulative frequency
>
> There's a FAQ by Nick Cox on tabulating cumulative frequency (or
> percent/proportion) as well as a couple of user-written
> commands that'll do
> it directly (-distplot- by Nick Cox and -ghistcum- by Baum and Cox).

-distplot- gives a continuous curve, not a bar graph.

If you really do want a bar graph, you can knit your own
in a few lines:

. u auto
. bysort rep78 : gen freq = _N if _n == 1
. replace freq = sum(freq)

!!! output edited here
. l freq

          freq
  1.         2
  2.         2
  3.        10
  4.        10
  9.        10
 10.        10
 11.        40
 12.        40
 38.        40
 39.        40
 40.        40
 41.        58
 42.        58
 56.        58
 57.        58
 58.        58
 59.        69
 60.        69
 68.        69
 69.        69
 70.        74
 73.        74
 74.        74

. label var freq "cumulative frequency"

. gra freq , mean bar by(rep78) b2(Repair record 1978) yla

In other words, calculate the cumulative
frequencies yourself and show them directly
as a bar chart.

The trickery lies in making sure that the
cumulative frequencies are the same within
category, so that their "mean" yields what
you desire. The "if _n == 1" is crucial here.
("* (_n == 1)" would work as well.)

Note that by default missings are ignored. Thus
the observations for which rep78 == . are not
represented in the bar graph.

Nick
[email protected]

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index