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   Fernando Sánchez <[email protected]>
To   <[email protected]>
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: [email protected]
[mailto:[email protected]] En nombre de Nick Cox
Enviado el: domingo, 30 de diciembre de 2012 10:19
Para: [email protected]
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 <[email protected]> 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 
> <[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/


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