[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: RE: rank ordered twoway graph
"Nick Cox" <firstname.lastname@example.org>
st: RE: RE: rank ordered twoway graph
Fri, 13 Jun 2008 16:39:21 +0100
Here's a program sketch. This is indicative, not definitive, and quite
untested. Although this is set up as a scatter plot, you can use
-recast()- to get other kinds of plot.
syntax varlist(min=2 max=2) [if] [in] [, * ]
* othervar incomevar [if] [in] [, <twoway_options> ]
count if `touse'
if r(N) == 0 error 2000
args other income
egen `rankvar' = rank(-`income') if `touse'
local what : var label `income'
if `"`what'"' == "" local what "`income'"
label var `rankvar' `"rank on `what'"'
twoway scatter `other' `rankvar' if `touse', `options'
Thanks, Nick. Your email nicely summarises the available solutions.
for being adamant to get a one line solution.
Short answer: No, it is not possible. But other solutions are easy.
For those following along, -qplot- is a program downloadable from the
Stata website given its publication in the Stata Journal. -search qplot-
-qplot- is best thought of as a considerable generalisation of the
official -quantile- command (with one cosmetic exception: -qplot- does
not show the tilted reference line that is a -quantile- default).
-qplot- plots ordered or sorted values (with some flexibility about how
sorted) versus cumulative fraction or rank (ditto), or indeed, via the
-xvariable()- option, versus any specified variable.
Shehzad's problem is different. Shehzad wants to plot something else
versus the ranks of (e.g.) income. This is not among the possibilities
of -qplot- at present. It might be accommodated by adding a
-yvariable()- option, but I am reluctant to do that. There is a fine
line between adding another feature that somebody might want and making
a program yet more complicated to use and understand, and indeed there
is, in this case, a risk of muddying the purpose of the program.
As previously implied, Shehzad's solution should be at worst two lines'
worth. Apart from what you can with -glcurve- (-findit- for locations),
there is a more direct solution:
egen rank = rank(income)
twoway <whatever> <somethingelse> rank
There is much scope for modifying that simple recipe. For example, the
usual convention is that the richest person is #1, and so forth, and
that is achievable in a flash:
egen rank = rank(-income)
Further, -egen, rank()- has options. Mapping to variously defined
cumulative fractions is also a step away. There is an FAQ on that:
FAQ . . . . . . . . . . Calculating percentile ranks or plotting
7/02 How can I calculate percentile ranks?
How can I calculate plotting positions?
Shehzad seems to be hankering after a one-line alternative to this
That's achievable with some programming, but as I said earlier I don't
think it exists at present.
Thanks, Nick. This is a very useful command to know. Now my question is:
using qplot I want to generate a graph of y-variable which is rank
by x-variable (obviously different from Pen's parade). If I used the
- xvariable - in - qplot -, it produces an x-axis over the entire range
variable but I am interested only in x-rank to sort my y-var. Is it
to do this using qplot?
You can make this possible in one line by writing a wrapper for those
commands, but I am not aware of any way to do that which is already
available. -qplot- (-search- for locations) allows plots of income
versus income rank, including a kind of graph which income people
associate with Jan Pen (although the same idea goes back much earlier).
I want to create a twoway graph (like spike or dropline) where the
is a rank variable (based on say income) and y-axis is the other
of interest (say health_pay). A simple command - twoway spike health_pay
income - spread the x-axis over the whole range of income but I am
interested in income rank and not income itself.
I know one way to do it is to generate income rank variable using -
- and then plotting the rank_var against health_pay but I was wondering
there was a direct method.
* For searches and help try: