Bookmark and Share

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

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

st: RE: yrescale cancels yscale(range()) in graphs by a categorical variable

From   Nick Cox <>
To   "''" <>
Subject   st: RE: yrescale cancels yscale(range()) in graphs by a categorical variable
Date   Thu, 21 Jun 2012 16:51:08 +0100

I don't have a good answer. The answer to many of these small -by:- problems is to tuck an extra option inside -by()- but that doesn't work here. 

I do have a work-around. 

sysuse auto
gen zero = 0
scatter price zero length, by(foreign, yrescale legend(off)) ms(Oh none) ytitle("`: var label price'")

Here you have a variable that is identically zero and so forces the scale to begin at zero. But you have to zap the legend and marker symbol that you don't want and reinstate the axis title that you do want. 


Toby Robertson

I want to create a set of plots of y on x according to values of a categorical variable c. I would like each plot a) to have its own scale for the y-axis, but b) to begin from zero.The basic syntax 
- twoway scatter y x, by(c)
creates separate graphs with a common y-axis scale, not necessarily starting from zero.
To achieve (a) a separate y-axis scale for each graph (but not necessarily starting from zero) I can use:
- twoway scatter y x, by(c, yrescale)
To have (b) each y-axis start from zero (but with a common scale for all of them) I can use:
- twoway scatter y x, by(c) yscale(range(0))
However, the combination of the two does not achieve (a) and (b).  The -yscale(range(0))- option has no effect.
- twoway scatter y x, by(c, yrescale) yscale(range(0))
What to do? This must be a common enough requirement. Without understanding Stata's graphic object model too well, I think there ought to be a parameter in the yrescale option such as yrescale(min(0)) that would let me do this easily, but there is not. A workaround involving combining separate graphs by category seems tedious.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index