Statalist The Stata Listserver


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

Re: st: RE: why not %#.#p format?


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: RE: why not %#.#p format?
Date   Thu, 05 Oct 2006 15:22:47 -0400

Nick,

Agree it would only fill a small hole in Stata, but it
seems like a fairly cheap and easy one to fill.

cheers,
Jeph










Nick Cox wrote:
I proposed something like this to Bill Gould a while
ago. Evidently I wasn't persuasive. In such matters
it can be difficult to decide whether my idea was
not that good, or Bill was being stubborn, or both,
but usually it's the first of these. Or so I now
think in this case.

Dividing up some of the possibilities, a format with
an extra percent sign for a numeric variable would mean
that "%" appeared after (e.g.) every value in a -list-.
I find it a little difficult to believe that anyone
really wants this, but a work-around is to create
a string variable, with the recipe

gen strvar = string(numvar) + "%"

which can be formatted to desired precision using an additional
-format()- argument inside -string()-. (Putting
a "%" sign in a row or column header, e.g.,
evidently, is not a matter of variable formats.)

Showing something that is a proportion on
a percent scale can be done
easily on the fly with -display-. Consider

.  local p 0.42

. di %3.0f 100 * `p' "%"
 42%

Finally, suppose that you have a variable
on a zero-one scale, but you want a graph
to show percents. Apart from the obvious
solution, multiply by 100, another way
to tackle this is with -mylabels- from SSC.

. sysuse auto, clear

. gen foo = uniform()

. scatter foo mpg

. mylabels 0(10)100, myscale(@/100) local(labels)
0 "0" .1 "10" .2 "20" .3 "30" .4 "40" .5 "50" .6 "60" .7 "70" .8 "80" .9 "90" 1 "100"

. scatter foo mpg, yla(`labels')

What -mylabels- does is produce a macro containing the axis values and the
labels (text) to be shown at those positions.

Of course, you can type out such labels directly, but -mylabels-
is an alternative, particularly when you want automation.

In short, I don't think this is needed that much, but
there are one-line work-arounds for all the cases I can
think of.

Nick
[email protected]

Jeph Herrin

Once again I find myself wondering what the logical or other
barriers are to Stata supporting a "percentage" format type.

I often have variables that are percentages, but to display
or graph them I have to create a second variable = pctvar*100
and put a "%" in the display statement. How much more elegant
if I could simply, eg,

  format pctvar %6.1p

and know that this variable will be displayed as 100x the contents
with a trailing "%" (one of the 6 chars of course). It seems like
a fairly modest variation on the %#.#e format; is there some obvious
logical or technical barrier to this? Or maybe there's a trick I
don't know for producing this?

Apologies if this has come up before, I searched the archives with
no luck.
*
*   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/


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



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