In a separate posting, I announced the updating of -tabplot- on
SSC.
-tabplot- uses a new unofficial -egen- function which has other
possible uses, especially for those who wish to devise their own
graphs. What follows has relevance especially for those
* using Stata 8
* sometimes wishing to go outside the repertoire of official graph
types
* accustomed to a little do-file work
and so others may wish to bail out now.
=======================================
The new function is called -axis()-. It is installed if you
install -tabplot-. I should, sooner or later, document it properly
somewhere, say within -egenmore- on SSC, but what follows is too
lengthy for a standard help file.
It is easiest to explain what -axis()- does by example. Indeed,
once examples are understood, it is trivial.
With the auto data,
. egen axis1 = axis(make) if foreign
produces this
. l axis1 make if foreign
+---------------------------------+
| axis1 make |
|---------------------------------|
53. | Audi 5000 Audi 5000 |
54. | Audi Fox Audi Fox |
55. | BMW 320i BMW 320i |
...
72. | VW Rabbit VW Rabbit |
|---------------------------------|
73. | VW Scirocco VW Scirocco |
74. | Volvo 260 Volvo 260 |
+---------------------------------+
and underneath the labels, -axis1- is just integers 1/22.
. l axis make if foreign, nola
+------------------------+
| axis1 make |
|------------------------|
53. | 1 Audi 5000 |
54. | 2 Audi Fox |
55. | 3 BMW 320i |
...
72. | 20 VW Rabbit |
|------------------------|
73. | 21 VW Scirocco |
74. | 22 Volvo 260 |
+------------------------+
You are correct if this reminds you of the results of the official
-egen- function -group()- with the -label- option. -axis()- sorts
on the varlist specified and assigns integers 1 up to the distinct
values, and by default assigns value labels according to the
varlist specified.
There are twists to -axis()- that distinguish it from -group()-.
. egen axis2 = axis(mpg make) if foreign , label(make)
(52 missing values generated)
. sort axis2
-axis()- now sorts on -mpg- (breaking any ties by -make-), but the
labels are entirely from -make-:
. l axis2 mpg make if foreign
+---------------------------------------+
| axis2 mpg make |
|---------------------------------------|
1. | Peugeot 604 14 Peugeot 604 |
2. | Audi 5000 17 Audi 5000 |
3. | Volvo 260 17 Volvo 260 |
...
20. | Datsun 210 35 Datsun 210 |
|---------------------------------------|
21. | Subaru 35 Subaru |
22. | VW Diesel 41 VW Diesel |
+---------------------------------------+
. l axis2 mpg make if foreign, nola
+------------------------------+
| axis2 mpg make |
|------------------------------|
1. | 1 14 Peugeot 604 |
2. | 2 17 Audi 5000 |
3. | 3 17 Volvo 260 |
...
20. | 20 35 Datsun 210 |
|------------------------------|
21. | 21 35 Subaru |
22. | 22 41 VW Diesel |
+------------------------------+
Now we are in a position to use the new axis variable as one axis
of a graph, hence the name. For example, if you want a display
similar to, but a little different from, that of -graph hbar- or
-graph dot- you can make your own without any programming:
. twoway spike mpg axis2 if foreign, hor
yla(1/22, noticks valuelabel ang(h))
xsc(r(0,.)) ytitle(" ")
Two further twists are shown by the results of
. egen axis3 = axis(for rep78), gap
(5 missing values generated)
The new labels run
"Domestic 1"
"2"
"3"
"4"
"5"
"Foreign 3"
"4"
"5"
which look not too bad when set out horizontally. To put it
another way, the labels are _not_ just a concatenation of the
labels or values of the variables specified, say
"Domestic 1"
"Domestic 2"
"Domestic 3"
...
which, at least to my taste, looks fairly awful on a graph axis.
(They are also not as nice as what -graph bar-, -graph hbar- and
-graph dot- do by themselves. But beggars can't be choosers.)
Also, that -gap- option implies that the underlying integers are
+-------------------------+
| foreign rep78 axis3 |
|-------------------------|
| 0 1 1 |
| 0 2 2 |
| 0 3 3 |
| 0 4 4 |
| 0 5 5 |
|-------------------------|
| 1 3 7 |
| 1 4 8 |
| 1 5 9 |
+-------------------------+
i.e. there is a gap between 1/5 and 7/9 which would show up on
a graph axis.
In short, -axis()- is a tool for "do-it-yourself" categorical axis
variables, after which some -twoway- graph to your design is one
step closer. Customising confidence interval or similar displays
is one class of examples.
There are more details, but if you're interested they will
become apparent on scrutiny of _gaxis.ado.
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/