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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: RE: RE: setting axis scale to maximum value of a variable


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: RE: setting axis scale to maximum value of a variable
Date   Mon, 11 Jun 2012 11:16:03 +0100

-range()- needs two arguments, even if one is missing. 

`= 50 * ceil(r(max)/ 50)' will give a multiple of 50 and round up. 

`= 50 * floor(r(max) / 50)' will give a multiple of 50 and round down.

See also 

SJ-3-4  dm0002  . . . . . . . . Stata tip 2: Building with floors and ceilings
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/03   SJ 3(4):446--447                                 (no commands)
        tips for using floor() and ceil()

Nick 
n.j.cox@durham.ac.uk 


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tim Evans
Sent: 11 June 2012 11:06
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: RE: RE: setting axis scale to maximum value of a variable

Nick,

Thanks for the -format- tip. I now have this sorted in the code now shown below. But to setting the max I think I have a partial solution, but not sure how I can pull in the value from -r(max)-

I propose summarising the crude rate and then setting this in the -ylab- option:

using this:

 yscale(range(`=r(max)'))

But I would like to make sure that I override the default so that it always goes to the nearest 50 on the yscale

using 

*/ yscale(range(`=r(max)')) /* 
*/ ylabel(0 (50) 5 * ceil(`=r(max)'/5), gmax  angle(horizontal) format(%3.0f)) /*

however, I get the following error:

invalid label specifier, :  * ceil(177.5696961057215/5):

I've also tried -round- but I think whatever I do wrong with -ceiling- is happening for -round- also.




levelsof age_grp, local(levels)
foreach l of local levels {
su crude if age_grp==`l'
line crude yydx if surg==2 & age_grp==`l', lpattern("l") || line crude yydx if surg==1 & age_grp==`l',  lpattern("_")|| line crude yydx if surg==99 & age_grp==`l', lpattern(".._..") xaxis(1 2) ,  /*
*/ yscale(range(`=r(max)')) /* 
*/ ylabel(0 (50) 5 * ceil(`=r(max)'/5), gmax  angle(horizontal) format(%3.0f)) /* 
*/ xlabel(2001, axis(1)) xtitle("Year", size(small) axis(2)) xtitle("", axis(1)) plotregion(lstyle(none)) /*
*/ ytitle("Rate per 100,000 women", size(small)) title("`: label (age_grp) `l''", size(medsmall)) /*
*/ legend(label(3 "All breast cancer") /*
*/ label(2 "Mastectomy") label(1 "Breast surgery")) /*
*/ legend(region(lstyle(none)) rows(1) size(small) lcolor(none))
}

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 11 June 2012 10:31
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: RE: setting axis scale to maximum value of a variable

First question: -ylabel()- has a -format()- suboption which you can use to override the default (which Stata will pick up otherwise from the display format of your y axis variable). This is documented at -help axis label options-. 

Second question is more obscure to me. Perhaps studying the options and suboptions as above will indicate a solution. Or assign value labels to your y axis variable. 

Nick 
n.j.cox@durham.ac.uk 

Tim Evans

I have two questions, the first one is, how do I set the formatting of the y axis when graphing twoway so that I don't display any significant figures - i.e I want to show 150 and not 150.00 as I currently have.

The second question is, I am running a loop of graphs on rates that I have generated. However, the scale I set in the twoway line graph may not be appropriate for each version of the graph I generate. So for instance I have 3 age groups 0-49, 50-64 and 64-79, the maximum value for 'crude' is say 100 for 0-49, 300 for 50-64 and 400 for 64-79. Defaulting the y-axis to 400 (as I am currently doing) will make the 0-49 graph look odd as it wont be scaled appropriately. 

Is there a way that I can specify in the options that the y-axis is only scaled up to the nearest 10 of the maximum for each iteration of the loop?

My code is this:

levelsof age_grp, local(levels)
foreach l of local levels {
line crude yydx if surg==2 & age_grp==`l', lpattern("l") || line crude yydx if surg==1 & age_grp==`l',  lpattern("_")|| line crude yydx if surg==99 & age_grp==`l', lpattern(".._..") xaxis(1 2) ,  /*
*/ ylabel(0 (50) 400, gmax angle(horizontal)) /*
*/ xlabel(2001, axis(1)) xtitle("Year", size(small) axis(2)) xtitle("", axis(1)) plotregion(lstyle(none)) /*
*/ ytitle("Rate per 100,000 women", size(small)) title("`: label (age_grp) `l''", size(medsmall)) /*
*/ legend(label(3 "All breast cancer") /*
*/ label(2 "Mastectomy") label(1 "Breast surgery")) /*
*/ legend(region(lstyle(none)) rows(1) size(small) lcolor(none))
}


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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