Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: about stacked mean bar chart

From   "Nick Cox" <>
To   <>
Subject   st: RE: about stacked mean bar chart
Date   Fri, 1 Nov 2002 09:52:18 -0000

Xiaoqu Luo
> I want to creat stacked bar chart where each bar stands for 
> the mean of a variable. I tried using "graph v1 v2 v3, bar 
> means by (v4) stack" to produce this but STATA said that it 
> was invalid. It looks like "stack" cannot be used with 
> means (i.e. "stack" option can only have the bar to 
> represent counts). Do you have any idea to do  stacked bar 
> chart on mean?

I guess that -graph, bar- was written with 
the notion that people might want to stack 
totals, but not means. 

One work-around would be as follows: 

1. Create variables which are means
and give them the same variable labels as
the originals:  

foreach v of var v1 v2 v3 { 
	bysort v4 : egen mean`v' = mean(`v') 
	_crcslbl mean`v' `v' 

2. Select just one observation from each 

	egen tag = tag(v4) 

3. Draw the graph 

	graph meanv1 meanv2 mean3 if tag, bar stack 

*   For searches and help try:

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