Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Histogram plot with frequency percentage and number of cases


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Histogram plot with frequency percentage and number of cases
Date   Sun, 30 Dec 2012 09:12:16 +0000

By "unique function" I understand "single command". I think you need
some warm-up, but it's not difficult to do it with a few commands.

Below the offset "freq + 1" is empirical; your constant may differ from 1.

Nick

sysuse auto, clear
bysort rep78 : gen freq = _N
count if rep78 < .
local total = r(N)
gen mylabel = string(freq) + "   (" + string(100 * freq / `total' ,
"%2.1f") + "%)"
twoway bar freq rep78, barw(0.9) || scatter freq rep78 , ms(i)
mla(mylabel) mlabpos(0)
gen freq2 = freq + 1
twoway bar freq rep78, barw(0.9) || scatter freq2 rep78 , ms(i)
mla(mylabel) mlabpos(0) legend(off) ysc(off)


On Sat, Dec 29, 2012 at 10:59 PM, Fernando Sánchez
<[email protected]> wrote:

> I am interested in plotting an histogram that shows over each of its bars
> the percentage and number of cases in this way: 7 (25%). Up till now I have
> been able to draw an histogram with the percentage and a barplot with the
> number of cases but not all in a unique chart.
>
> The question is as follows: Is it possible to do it with a unique function
> in the same chart?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index