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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: How to change scale of yaxis from proportion with lots of decimals to per 100000


From   Maarten Buis <maartenlbuis@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to change scale of yaxis from proportion with lots of decimals to per 100000
Date   Fri, 16 Nov 2012 10:40:38 +0100

On Fri, Nov 16, 2012 at 8:47 AM, roland andersson wrote:
> I want to make twoway graphs of the trend over time of the incidence
> rate of a rare disease by four groups where this disease varies
> strongly. In one group the disease has changed from 5 to 10 per
> 100,000 live births, in another from 5000 to 10,000 per 100,000 live
> births.
> I want to do the graphs by(groups). My problem is that the yscale
> shows the proportion with lots of decimals, eg 0.00005. I want to
> multiply the yscale with 100,000 so that it shows the number per
> 100,000 live births instead of the proportion with decimals. How can I
> do it?

With such big differences it becomes almost unavoidable to work on a
log scale. Also you will always end up with lots of zeros, either
before or after the decimal point. Depending on your audience you can
avoid this by displaying numbers in exponential format, i.e. 500,000 =
5 * 10^5. This often works well for labeling axes on a log scale,
though it may not be the best choice for all audiences. When the
exponential format is not useful, it is often helpful to use the
-%#.#gc- format for large numbers instead of the default format, so it
displays 500000 as 500,000.

*----------------- begin example ------------------
drop _all
set obs 51
gen year = 1959 + _n
gen group_a = runiform()*5e-5 + 5e-5
gen group_b = runiform()*.05 + .05

// proportion
twoway line group_a group_b year, yscale(log) ///
    ylab(5e-5 "5{c 215}10{sup:-5}" ///
         1e-4 "1{c 215}10{sup:-4}" ///
         5e-4 "5{c 215}10{sup:-4}" ///
         1e-3 "1{c 215}10{sup:-3}" ///
         5e-3 "5{c 215}10{sup:-3}" ///
         1e-2 "1{c 215}10{sup:-2}" ///
         5e-2 "5{c 215}10{sup:-2}" ///
         1e-1 "1{c 215}10{sup:-1}") ///
    ytitle("proportion (log scale)") ///
    name(prop, replace)

// per 100,000	
gen p1e5_a = group_a * 1e5
gen p1e5_b = group_b * 1e5

twoway line p1e5_a p1e5_b year, yscale(log) ///
    ylab(5e0 "5{c 215}10{sup:0}" ///
         1e1 "1{c 215}10{sup:1}" ///
         5e1 "5{c 215}10{sup:1}" ///
         1e2 "1{c 215}10{sup:2}" ///
         5e2 "5{c 215}10{sup:2}" ///
         1e3 "1{c 215}10{sup:3}" ///
         5e3 "5{c 215}10{sup:3}" ///
         1e4 "1{c 215}10{sup:4}") ///
    ytitle("per 100,000 biths (log scale)") ///
    name(p1e5, replace)
	
// same, but without exponential notation	
twoway line p1e5_a p1e5_b year, yscale(log) ///
    ylab(5e0 1e1 5e1 1e2 5e2 1e3 5e3 1e4,   ///
         format(%8.0gc))                    ///
    ytitle("per 100,000 biths (log scale)") ///	
    name(noexp, replace)
*------------------ end example -------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   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