Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

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


From   Fernando Sánchez <fsanchez@euclides.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Histogram plot with frequency percentage and number of cases
Date   Sun, 30 Dec 2012 10:28:51 +0100

Dear Dr. Cox, many thanks for your answer. Both codes work perfectly. Now I
am going to implement with your data. You are right that I need some warm
up. I am starting my learning process with Stata.

Kindest regards,

Fernando

-----Mensaje original-----
De: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] En nombre de Nick Cox
Enviado el: domingo, 30 de diciembre de 2012 10:19
Para: statalist@hsphsun2.harvard.edu
Asunto: Re: st: Histogram plot with frequency percentage and number of cases

This also works, for "different values of 32".

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(12) ysc(r(. 32) off) legend(off)


On Sun, Dec 30, 2012 at 9:12 AM, Nick Cox <njcoxstata@gmail.com> wrote:
> 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 
> <fsanchez@euclides.com> 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/


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index