[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: gr bar for string variable

From   "Nick Cox" <>
To   <>
Subject   st: RE: gr bar for string variable
Date   Fri, 7 Mar 2008 19:16:05 -0000

b. water: 

You asked about bar graphs in January. In that thread -catplot- from SSC
was flagged as an 
alternative to do-it-yourself counting and graphing. That remains true
for your questions 

Here is an example. 

sysuse auto, clear 
catplot hbar foreign rep78, percent(rep78) asyvars bar(1, bcolor(pink))
bar(2, bcolor(blue))

-catplot- can calculate percents. With your route, you would have to do
more work before you 
called the graph command. 

-catplot- can give you different colours. You use the option -asyvars-.
That's just the 
same option as -graph bar-, -graph hbar-, etc. It's tacit that -asyvars-
gives different
colours, but think of it this way: if -graph- knows that it is showing
separate variables, it 
knows that it must show them distinctively. You can control the colours
by calling up -bar(,)- 
as desired. 

The example doesn't use string variables, but -catplot- will handle them
without demur. 


b. water

stata 8.2,

i have data set-up like this:

injurytype	year
typeII	2007
minimal	2003
typeII	2003
minimal	2003
typeIII	2005
typeIV	2006

and so on (the range of the injury type is minimal, typeI to typeIV
while the year is 2003 - 2007).

i am building a graph bar like the one in stata v. 8 [G] page 135 where
in place of region 1 in the example, i would have the year and instead
of 1 to 9 regional division, i would have the 5 types of injury (i.e.
minimal, typeI to typeIV). following my earlier query (around new year's
time), i did:

gen x=1
gr bar (count) x, over(injurytype) over(year)

which produces the one of the graph that i want except for one thing:
the injury types, displayed on x-axis suffered from 'overprinting'. i
know i can try:

gr hbar (count) x, over(injurytype) over(year) ysize(10)

which did solve the overprinting but i would be grateful if anyone can
tell me:

1. how can i make, instead, each bar to be of a different color and
displaying the color legend (e.g. red for minimal etc), so that i can
suppress injurytype being shown on the x-axis (but still displaying the
year) (someone need to tell me how to achieve this), and

2. how can i, instead of a -count-, produce a proportion or percentage
of each type of injury over (year) i.e. on a graph bar, the y-axis would
shows either proportion or percentage rather than count.

*   For searches and help try:

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