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

From |
Ernest Berkhout <ernestb@seo.fee.uva.nl> |

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

Subject |
Re: st: RE: Formaatin the labels of the histogram-bars ? |

Date |
Thu, 27 Nov 2003 17:48:07 +0100 |

At 16:37 27-11-2003, Nick Cox wrote:

Thanks Nick, that is a 'relatively straightforward workaround' which worked for me. Finally most solutions seem to come down on creating your own labels in some kind of variable and than switch to the twoway-concept. On the other hand, I don't see why in this particular case Stata did not include some 'mlabformat', to cure irregular labeling...I seem to remember a previous thread pointing to the absence of -mlabformat()-. I tried generating a _string_ variable to use under -addlabopts()- in -histogram-, but got nowhere. However, this convoluted work-around may be of interest. bysort rep78 : gen count = _N count if rep78 < . gen density = count / r(N) gen sdensity = string(density, "%4.3f") twoway bar density rep78, bstyle(histogram) || scatter density rep78, ms(none) mlabel(sdensity) mlabpos(12) OR twoway histogram rep78, discrete || scatter density rep78, ms(none) mlabel(sdensity) mlabpos(12)

I just made a few small alterations to Nick's solution that might be of interest in case people want to label the percentages instead of fractions. Further, as I have 130.000 records I 'tagged' only one record within each category to speed up the second part (the labeling) of the graph. So full syntax would then become:

*** for percentages & large datasets: ***

bysort rep78 : gen count = _N

count if rep78 < .

gen density = 100*count / r(N) <-- changed -->

gen sdensity = string(density, "%4.1f")

egen tag = tag(rep78) <-- new -->

twoway histogram rep78, discrete percent || <-- changed -->

scatter density rep78 if tag, ms(none) mlabel(sdensity) mlabpos(12) <-- changed -->

OR, equivalent with the bars:

twoway bar density rep78 if tag, bstyle(histogram) || <-- changed -->

scatter density rep78 if tag, ms(none) mlabel(sdensity) mlabpos(12) <-- changed -->

Note that in the histogram-option the histogram has to use all records to calculate the right percentages, so I did not leave my tag on that line...

Ernest Berkhout

SEO Amsterdam Economics

University of Amsterdam

Room 3.08

Roetersstraat 29

1018 WB Amsterdam

The Netherlands

tel.:+ 31 20 525 1657

fax:+ 31 20 525 1686

http://www.seo.nl

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

A statistician: someone who insists

on being certain about uncertainty

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

*

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

**References**:**st: Formaatin the labels of the histogram-bars ?***From:*Ernest Berkhout <ernestb@seo.fee.uva.nl>

**st: RE: Formaatin the labels of the histogram-bars ?***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: logarithmic scales** - Next by Date:
**st: Simultaneous Tobit Models with ml** - Previous by thread:
**st: RE: Formaatin the labels of the histogram-bars ?** - Next by thread:
**st: Extracting a scalar from a matrix** - Index(es):

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