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 on April 23, and its replacement, is already up and running.

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

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

From   "Kaulisch, Marc" <>
To   <>
Subject   AW: st: Suppress unused values of categorical var in graph? (Stata 11)
Date   Sun, 14 Aug 2011 21:22:41 +0200

Stupid me, haven't thought about that solution because I used "egen group" only with two or more vars... Your solution is very handsome.
Of course, my problem is self-inflicted but in some cases it is useful that values of categorical variables are not equally spaced.


-----Ursprüngliche Nachricht-----
Von: [] Im Auftrag von Nick Cox
Gesendet: Sonntag, 14. August 2011 17:53
Betreff: Re: st: Suppress unused values of categorical var in graph? (Stata 11)

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:

*   For searches and help try:

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