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:graph mean with missing groups

From   Nick Cox <>
Subject   Re: st:graph mean with missing groups
Date   Sun, 15 Jul 2012 19:18:19 +0100

This seems puzzling and contradictory to me, which may explain the
lack of replies.

If groups are empty then the mean of any other variable is undefined
and Stata's refusal to plot the mean is reasonable. It is unknown, or
missing, and not 0.

On the other hand if what Amanda wants is some kind of histogram or
bar chart, then that can be obtained directly e.g. by -histogram- or
-twoway histogram- and Stata will show empty groups as having zero
frequency, or percent, or density. Such a histogram can be forced to a
line chart by e.g.

twoway histogram ... , recast(line)


On Sat, Jul 14, 2012 at 1:13 AM, Amanda Fu <> wrote:

> I am stuck with drawing a graph about means of a test score variable
> by groups. The problem is caused by there are some "empty" groups.
> The variable "score" range from 0 to 100. I cut it into 10 bands : 0,
> 1-10, 11-20,21-30,...,91-100. I create a new variable "score_percent"
> indicates the percent for the share of observations in each band.
> The data set is like:
> id   score   score_percent
> 1      32           3.8         (Totally 3.8% observations have scores
> between 31-40)
> 2      89         23.4
> 3      67         16.5
> ...................
> I tried to use the following command to create a graph for mean level
> of test scores:
> .twoway connected   score_percent    score ,xlabel(0(10)100)
> -------------------------
> However, in the data set none observations have scores from 11-20. So
> this is an empty band. The value of "score_percent" for this band
> should be 0. But if I use the above command to draw the graph, the
> connected line will skip the empty band and directly jump to the next
> point (it is like, along the x-axis there are band 0-10, 21-30,.....).
> What I wanted is to give the empty band with percent share is 0.
> I wonder if someone can give me some suggestion how to fix this. Thank you!
*   For searches and help try:

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