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]

Re: st: Suppress unused values of categorical var in graph? (Stata 11)

From   Nick Cox <>
Subject   Re: st: Suppress unused values of categorical var in graph? (Stata 11)
Date   Sun, 14 Aug 2011 16:53:18 +0100

Marc's problem could be regarded as self-inflicted. He creates a
variable with values 1, 4, 6, 8, 12 and then complains that the values
when supplied as one axis of a -twoway graph- are not plotted with
equal spacing.

More seriously: Marc's problem is certainly that -twoway- has no
notion of a categorical variable. However, two more lines of code
produce equal spacing:

egen group = group(for_eu), label
twoway rcap ub lb group, hori || scatter group mean, ///
legend(off) ytitle("") ylabel(1/5, valuelabel angle(0) nogrid)

I'll look into the problem with -ciplot- reported by Marc.


On Sun, Aug 14, 2011 at 1:02 PM, Kaulisch, Marc
<> wrote:
> I came across a problem with -ciplot- (from ssc) because option
> ytitle("") does not suppress the ytitle. As Nick Cox (author of ciplot)
> mentioned earlier that he does not touch ciplot anymore and one should
> use the statsby strategy (see Stata Journal 10, 1, p.143-151). I started
> to follow his advise but come to a point of dissatification and maybe
> some one can help me (still Stata 11 user).
> I have a categorical variable with categories ranging from 8 to 44 where
> some values in this range are not attached to any categories. Drawing a
> graph means that on the axis of this variable there is a lot of "unused"
> space. Is there a way to reduce this?  Is there a way to tell Stata that
> this is a categorical variable (factor variables are not allowed...)?
> (Of course a recode of the cat var would do the trick but why should
> this be the only option?)
> My example code with the auto dataset
> sysuse auto
> recode foreign (0=1) (1=4), gen(for_eu)
> replace for_eu = 6 if regexm(make, "Renault")
> replace for_eu = 8 if regexm(make, "VW")
> replace for_eu = 12 if regexm(make, "Audi")
> statsby mean=r(mean) ub=r(ub) lb=r(lb) N=r(N), clear by(for_eu): ci
> weight
> levelsof for_eu, local(fe)
> twoway rcap ub lb for_eu, hori || scatter for_eu mean, ///
> legend(off) ytitle("") ylabel(`fe', valuelabel angle(0) nogrid)

*   For searches and help try:

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