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

st: Re: Bar chart and time series


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Bar chart and time series
Date   Thu, 26 May 2005 14:54:32 -0700 (PDT)

Problem solved. The solution requires -twoway bar- as Nick suggested.
Another list member contacted me privately and pointed me in the
right direction with a few lines of code.

sysuse educ99gdp, clear
gen public04 = 1.2*public
gen private04 = 1.2*private
expand 2
sort country
gen group = mod(_n,2)
sort country group
gen public1999 = public if group==0
gen public2004 = public04 if group==0
gen private1999 = private if group==1
gen private2004 = private04 if group==1
encode country, gen(ccode)
replace ccode=ccode+.2 if group==1
replace ccode=ccode-.2 if group==0
#delimit ;
tw bar public2004 ccode , barw(0.4) || bar private2004 ccode,
barw(0.4) || bar public1999 ccode, barw(0.4) || bar private1999
ccode, barw(0.4) xla(1 2 3 4 5 6 7 8 9 10, alternate val);

Friedrich

--- Nick Cox <[email protected]> wrote:
> This seems in essentially the same territory
> as Margo Schlanger's question yesterday and 
> so my answer resembles the one given to her. 
> 
> I am not clear what your "guidelines" are, 
> but they sound like a boss with inflexible 
> views. Anyway, I am pretty clear that -graph bar- 
> was never really intended for time series data. 
> 
> Given some preternatural predisposition to a
> bar chart here, you should go straight for 
> -twoway bar- here, and forego the categorical 
> imperative, here so much cant (Kant?). 
> 
> Nick 
> [email protected] 
> 
> Friedrich Huebler
>  
> > Stata 8.2, Windows XP
> > 
> > I would like to create a bar chart that compares country data
> > over time but am not sure how to do this. Take this example:
> > 
> > . sysuse educ99gdp, clear
> > . graph bar public private, over(country)
> > 
> > The graph shows 1999 data. Now assume that I have 2004 data that
> > I want to add to the graph. Assume further that all 2004 values
> > are higher than the 1999 values.
> > 
> > . gen public04 = 1.2*public
> > . gen private04 = 1.2*private
> > 
> > One possibility would be to add the 2004-1999 difference on top
> of
> > the existing bars, in a stacked bar chart. Another possibility
> would
> > be to add points or other symbols above the "public" and
> "private"
> > bars that indicate the 2004 value. I don't know how to do either
> in
> > Stata and so far I managed only to create a graph that has too
> > many bars.
> > 
> > . graph bar public public04 private private04, over(country)
> > 
> > I studied the Graphics manual and Michael Mitchell's "A visual
> guide
> > to Stata graphics" but found no other solution. Dot plots are not
> an
> > option because I have to follow certain guidelines. Thank you for
> > your suggestions on how the data could be presented.



		
__________________________________ 
Discover Yahoo! 
Stay in touch with email, IM, photo sharing and more. Check it out! 
http://discover.yahoo.com/stayintouch.html
*
*   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