# st: RE: Re: Bar chart and time series

 From "Nick Cox" <[email protected]> To <[email protected]> Subject st: RE: Re: Bar chart and time series Date Thu, 26 May 2005 23:40:34 +0100

```This can be simplified a bit while
keeping the same idea. You don't need
to change the basic data structure.

sysuse educ99gdp, clear
gen public04 = 1.2*public
gen private04 = 1.2*private
encode country, gen(ccode)
gen ccode2 =ccode+.2
replace ccode = ccode-.2
#delimit ;
tw bar public04 ccode , barw(0.4) || bar private04 ccode2,
barw(0.4) || bar public ccode, barw(0.4) || bar private
ccode2, barw(0.4) xla(1 2 3 4 5 6 7 8 9 10, alternate val);

Note that this solution hinges on -public04- and -private04-
being greater than -public- and -private- respectively,
so that the later bar laid down first does not obscure the
earlier bar laid down second.

Nick
[email protected]

Friedrich Huebler

> 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);

Nick Cox

> > you should go straight for
> > -twoway bar- here

*
*   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/
```