Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Nick Cox <[email protected]> |

To |
"'[email protected]'" <[email protected]> |

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

Date |
Mon, 11 Jun 2012 11:40:00 +0100 |

I didn't see the bottom of the previous post. To explain: -graph- won't do any of those calculations on the fly. Those must all be done in advance. So, the whole of the expression must be evaluated by the parser before -graph- sees it. Not ylabel(0 (50) 5 * ceil(`=r(max)'/5) but ylabel(0 (50) `=5 * ceil(r(max)/5)') Nick [email protected] -----Original Message----- From: Nick Cox Sent: 11 June 2012 11:16 To: '[email protected]' Subject: RE: RE: RE: setting axis scale to maximum value of a variable -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 [email protected] -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Tim Evans Sent: 11 June 2012 11:06 To: '[email protected]' 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: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox Sent: 11 June 2012 10:31 To: '[email protected]' 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 [email protected] 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/

**References**:**st: Sppack vs spatgsa***From:*<[email protected]>

**st: setting axis scale to maximum value of a variable***From:*Tim Evans <[email protected]>

**st: RE: RE: setting axis scale to maximum value of a variable***From:*Tim Evans <[email protected]>

**st: RE: RE: RE: setting axis scale to maximum value of a variable***From:*Nick Cox <[email protected]>

- Prev by Date:
**st: RE: RE: RE: setting axis scale to maximum value of a variable** - Next by Date:
**st: RE: RE: RE: RE: setting axis scale to maximum value of a variable** - Previous by thread:
**st: RE: RE: RE: setting axis scale to maximum value of a variable** - Next by thread:
**st: RE: RE: RE: RE: setting axis scale to maximum value of a variable** - Index(es):