Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: labels on bar graphs


From   "Martin Weiss" <martin.weiss@uni-tuebingen.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: labels on bar graphs
Date   Mon, 30 Jun 2008 10:14:46 +0200

All these clever solutions have a funny tendency to remind me of one thing:
a software that takes prides in its graph capabilities should not force
users to go to such lengths for a mundane task like labeling with
percentages... 

Martin Weiss
_________________________________________________________________

Diplom-Kaufmann Martin Weiss
Mohlstrasse 36
Room 415
72074 Tuebingen
Germany

Fon: 0049-7071-2978184

Home: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1130

Publications: http://www.wiwi.uni-tuebingen.de/cms/index.php?id=1131

SSRN: http://papers.ssrn.com/sol3/cf_dev/AbsByAuth.cfm?per_id=669945

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Svend Juul
Sent: Monday, June 30, 2008 9:56 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: labels on bar graphs 


Rich wrote:

I need to produce a sizable number of bar graphs for a client. The
client wants the y-axis to be labeled as, e.g., "15%" rather than as,
e.g., .15. The range of proportions for these graphs varies quite a bit
(from a max of less than .05 to a max of over .2) so I don't want to
force them all to be the same.

After seeing a graph, it is easy enough to use the ylabel option to get
what I want. Given that I am generally willing to live with Stata's
automatic choice of tick marks, is there a way to automatically get
labels in the form I want (e.g., "15%") rather than the way Stata wants
(e.g., .15)?

======================================================================

You could -contract- the dataset, determine the maximum percent, and
create a macro containing a label corresponding to that. Here is an
example:

-------------------------------------------------------------
sysuse auto , clear
contract rep78 , percent(pct) nomiss
local pmax = r(max)/r(sum)

if `pmax' < .05 {
   local ylab `" 0 " 0% " 1 " 1% " 2 " 2% " 3 " 3% " 4 " 4% " 5 " 5% "
"'
}
else if `pmax' < .10 {
   local ylab `" 0 " 0% " 2 " 2% " 4 " 4% " 6 " 6% " 8 " 8% " 10 " 10% "
"'
}
else if `pmax' < .20 {
   local ylab `" 0 " 0% " 5 " 5% " 10 " 10% " 15 " 15% " 20 " 20% " "'
}
else  {
   local ylab `" 0 " 0% " 10 " 10% " 20 " 20% " 30 " 30% " 40 " 40% " 50
" 50% " "'
}

graph bar pct , over(rep78) ylabel(`ylab')
-------------------------------------------------------------

Hope this helps
Svend




__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone:  +45 8942 6090
Home:   +45 8693 7796
Email:  sj@soci.au.dk
__________________________________________ 

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

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