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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: RE: RE: labels on bar graphs |

Date |
Wed, 2 Jul 2008 00:28:12 +0100 |

Similarly, and as promised earlier, I've revised my -mylabels-. The previous version is on SSC; this version will follow when I've revised the help. The program is also short enough to be quotable. What are new in this version are options -suffix()- to indicate text to be appended to all labels and -prefix()- to indicate text to be prepended to all labels. You give it what you want to see, and how the numbers that the graph sees differ. . mylabels 0(5)20, local(labels) suffix(%) myscale(@/100) 0 "0%" .05 "5%" .1 "10%" .15 "15%" .2 "20%" . mylabels 0(5)20, local(labels) suffix(" %") myscale(@/100) 0 "0 %" .05 "5 %" .1 "10 %" .15 "15 %" .2 "20 %" . mylabels 0(5)20, local(labels) prefix("$") myscale(@) 0 "$0" 5 "$5" 10 "$10" 15 "$15" 20 "$20" *! NJC 1.1.0 2 July 2008 *! NJC 1.0.0 5 May 2003 program mylabels version 8 syntax anything(name=values) , MYscale(str) Local(str) /// [Format(str) PREfix(str) SUFfix(str)] numlist "`values'" local values "`r(numlist)'" if !index("`myscale'","@") { di as err "myscale() does not contain @" exit 198 } if "`format'" != "" { capture di `format' 1.2345 } foreach v of local values { local val : subinstr local myscale "@" "(`v')", all local val : di %8.0g `val' if "`format'" != "" local v : di `format' `v' local mylabels `"`mylabels' `val' "`prefix'`v'`suffix'""' } di as res `"{p}`mylabels'"' c_local `local' `"`mylabels'"' end Michael Blasnik I have written a brief ado to address this problem with graphs. It isn't fully automated in terms of selecting the specific numbers, but a wrapper to select "nice" numbers for the labeled ticks could be used. It's short enough that I can just list it: program define labpct version 9.2 args start step end decimals loc forvalues i=`start'(`step')`end' { local pct: di %5.`decimals'f `i'*100 local pct = trim("`pct'") local pctlist `"`pctlist' `i' "`pct'%" "' } c_local `loc' `"`pctlist'"' end The typical syntax is something like labpct 0 .02 .1 0 ylab The arguments are starting value, step value, max value, number of digits after decimal in the percentage, and name of local macro to contain the result. This command would result in a local macro called ylab that looks like this: di `"`ylab'"' 0 "0%" .02 "2%" .04 "4%" .06 "6%" .08 "8%" .1 "10%" A subsequent graph command could then be : graph ...., ylab(`ylab') On Tue, Jul 1, 2008 at 10:24 AM, Richard Goldstein <richgold@ix.netcom.com> wrote: > I agree that Nick's suggestion would solve my, and other people's, problem > completely > > I also did not understand Frank's comment > * * 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/

**Follow-Ups**:**Re: st: RE: RE: labels on bar graphs***From:*"Michael Blasnik" <michael.blasnik@gmail.com>

**References**:**Re: st: RE: RE: labels on bar graphs***From:*Richard Goldstein <richgold@ix.netcom.com>

**RE: st: RE: RE: labels on bar graphs***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**Re: st: RE: RE: labels on bar graphs***From:*Richard Goldstein <richgold@ix.netcom.com>

**Re: st: RE: RE: labels on bar graphs***From:*"Michael Blasnik" <michael.blasnik@gmail.com>

- Prev by Date:
**Re: st: Please say where user-written software you discuss comes from** - Next by Date:
**Re: st: RE: RE: labels on bar graphs** - Previous by thread:
**Re: st: RE: RE: labels on bar graphs** - Next by thread:
**Re: st: RE: RE: labels on bar graphs** - Index(es):

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