[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: Bar chart and time series
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
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
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);
--- Nick Cox <firstname.lastname@example.org> 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?).
> 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
> > the existing bars, in a stacked bar chart. Another possibility
> > be to add points or other symbols above the "public" and
> > bars that indicate the 2004 value. I don't know how to do either
> > 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
> > to Stata graphics" but found no other solution. Dot plots are not
> > option because I have to follow certain guidelines. Thank you for
> > your suggestions on how the data could be presented.
Stay in touch with email, IM, photo sharing and more. Check it out!
* For searches and help try: