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

st: RE: overlay bar and line graph


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: overlay bar and line graph
Date   Wed, 30 Jul 2003 18:23:05 +0100

Douglas Thomas

> I have looked all through manuals and web to do something 
> in Stata 8 that I thought would be straightfoward and 
> simple. I need to overlay a bar and line graph. The data 
> are not twoway. The x axis is categorical not numerical ( I 
> say this because I have seen the twoway overlaid graphs 
> option). On the X axis are days of the week. On the y axis 
> I want both raw numbers of responses to a simple question 
> (yes and no) represented by two bars and then also i want a 
> line showing the percentage of responses that are no (so 
> there would be another y scale (percent). Is this possible 
> to do? I have inserted a sample copy of the graph crated in Excel. 

I can't see your graph -- in any case please don't 
send attachments to Statalist. They 
are often unreadable to members, place a load on 
mailers and spread viruses. This has long been 
mentioned in the FAQ. 

On the graphics, the general point has been touched 
on several times since the release of Stata 8. Although 
you think of your x variable as categorical that is not 
ineluctable and day of the week sounds acceptably numeric
to me, and more importantly to Stata. One way forward is 
to produce a -twoway bar- and then superimpose a -twoway line-.  

I was able to make some progress on an auto 
data example which I hope is not too far from
what you want. You will need to fiddle around
with the two axis scales, but that is well
documented. 

. sysuse auto
. egen ones = sum(foreign == 1), by(rep78)
. egen zeros = sum(foreign == 0), by(rep78)
. egen pc = mean(100 * !foreign), by(rep78) 
. gen rep78_1 = rep78 - 0.1 
. gen rep78_2 = rep78 + 0.1
. sort rep78 
. twoway bar zeros rep78_1, barw(0.2) || 
	bar ones rep78_2, barw(0.2) || 
	line pc rep78 , 
	ytitle("#no, #yes and % no") xtitle(whatever) 
      legend(order(1 "# no" 2 "# yes" 3 "% no") row(1))

Hope this helps. 

Nick 
[email protected] 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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