[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Multiline Relabeling graph & plotting piecharts with foreach

From (Vince Wiggins, StataCorp)
Subject   Re: st: Multiline Relabeling graph & plotting piecharts with foreach
Date   Fri, 20 Jun 2008 09:47:17 -0500

Beth Gifford <> asks two questions about -graph-.  Scott
Merryman <> addressed the first, so I'll take the

> 2.  Pie Chart with Foreach: Different #'s of Slices In my pie chart,
> I wanted to plot the missing values as grey.  However, I am
> generating the same plot over multiple sites using foreach.
> Sometimes, one of the categories has 0 responses so there are
> different numbers of slices which throws off my desired color
> scheme.  Is there a way so that I can fix the colors based on the
> value of the slice?

Beth is using the -over(grpvar)- option to create pie charts whose slices
represent each level of -grpvar-.  She is also using an -if- or -in- condition
to create different graphs over different subsets of the data.  The problem is
that all levels of -grpvar- are not seen in each subset of the data, which
gives Beth a different number of slices on each graph and thus the slices for
same level of -grpvar- differ in color across the graphs.

The -allcategories- option of -graph pie- (and -graph bar-, -graph dot-, and
-graph box-) is designed for just this problem.  It specifies that the number
of levels in the graph include all of the levels of the -over()- variable(s)
from the whole dataset rather than just the levels for the subset of data
being graphed.  Obviously there are no pie slices for the levels that do not
occur in the subset, however those levels are included in the legend and the
color of the slices for each level will match across graphs of different

-- Vince

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index