Question

I am producing a number of charts in a loop, using example code below

forvalues i = 1/11 {
    local t: label (countryID) `i'
    twoway line Var1 Var2 Var3 year if countryID == `i', ylabel(, valuelabel grid ///
          angle(horizontal)) xlabel(1999(2)2013) xtitle("") ///
          lpattern("l" "dash_dot" "longdash") legend(size(small)) title("`t'")
    graph export output/PredictLaw`t'.png, replace
}

The values of each variable are labeled, but only at integer level. The variable itself can take any value between two integers, though. Consequently, I would like to ensure somehow that the yaxis uses only integers as distance, e.g. always in steps of 1.

However, since the range for each country is different, I would like Stata to determine how long the range of the y-axis has to be, as shorter ranges of course produce neater looking graphs. Hence, I would rather not use something in the form of ylabel(1(1)21, ....

Is there a way to define the spacing of the y-axis, while keeping the range of the y-axis a Stata determined variable?

Was it helpful?

Solution

After

summarize whatever, meanonly 

local ymin = floor(r(min)) 
local ymax = ceil(r(max)) 

give integer results you can invoke in graph calls. The small detail here that you round down the minimum, if you do any rounding, and round up the maximum, ditto, given floor() and ceil() functions, could add a smidgen of space that suits graphical purposes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top