Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Significant figures formats


From   [email protected] (William Gould, Stata)
To   [email protected]
Subject   Re: st: Significant figures formats
Date   Fri, 18 Jul 2003 11:19:17 -0500

Roger Newson <[email protected]> wrote, 

> I have been looking in -[U] 15.5 Formats: controlling how data are
> displayed-, but I cannot seem to find any formats for displaying data to k
> significant figures, except for the %w.de formats, which display data in the
> form x.ye-z. Ideally, if I have a data set with 1 observation per estimated
> parameter and data on confidence intervals and P-values, then I would like
> to be able to list the P-values to 2 significant figures, so that 4.5e-1
> would be listed as 0.45 and 4.5e-2 would be listed as 0.045 and 4.5e-5 would
> be listed as 0.000045

With Stata 8, try %9.2g, %8.2g, or %<w>.2g:

        . display %9.2g 4.52394e-3
            .0045

        . display %9.2g 4.52394e-5
          .000045       

Display value x with %<w>.<d>g, with d!=0, does not display significant
figures, but for |x|<1, it does.

Let me repeat something I wrote on 7apr2003:

------------------------------------------------------------------------------
I would like to mention the new-to-Stata-8 %<w>.<d>g and %<w>.<d>gc formats
when <d> is greater than 0.  I am not certain many of you noticed the change.

%12.0g, as you know, shows a number in field of width 12.  That number is
displayed in such away as to show as many of its digits as possible.

        ----+----1----+----2
         3.141592654          <- display %12.0g _pi
         31.41592654          <- display %12.0g _pi*10
         314159.2654          <- display %12.0g _pi*10^5
         314159265.4          <- display %12.0g _pi*10^8
          3141592654          <- display %12.0g _pi*10^9
         3.14159e+10          <- display %12.0g _pi*10^10

         3.141592654          <- display %12.0g _pi
         .3141592654          <- display %12.0g _pi*10^(-1)
         .0003141593          <- display %12.0g _pi*10^(-4)
         .0000314159          <- display %12.0g _pi*10^(-5)
         3.14159e-06          <- display %12.0g _pi*10^(-6)

I want to draw you attention especially to that last two lines:

         .0000314159
         3.14159e-06

Note how smart is %12.0g.  It could have displayed _pi*10^(-6) as

         .0000031415


but it knew that, if it switched to %e format, it could display an extra
digit, and so it did.  That's the purpose of the %g format:  to show as many
digits as possible within the specified width.

New to Stata 8, you can specify the maximum number of digits you want, which 
you specify as the <d> in %<w>.<d>g:

        ----+----1----+----2
               3.142          <- display %12.4g _pi
               31.42          <- display %12.4g _pi*10
                3142          <- display %12.4g _pi*10^3
              314159          <- display %12.4g _pi*10^5 
            31415927          <- display %12.4g _pi*10^7
          3141592654          <- display %12.4g _pi*10^9
           3.142e+10          <- display %12.4g _pi*10^10

               3.142          <- display %12.4g _pi
               .3142          <- display %12.4g _pi*10^(-1)
            .0003142          <- display %12.4g _pi*10^(-4)
           .00003142          <- display %12.4g _pi*10^(-5)
          3.1412e-06          <- display %12.4g _pi*10^(-6)

%12.4g is almost a 4-significant digit format, the exceptions being 

              314159          <- display %12.4g _pi*10^5 
            31415927          <- display %12.4g _pi*10^7 
          3141592654          <- display %12.4g _pi*10^9

To show those with 4 digits would have required either going to %e format:

          3.1412e+05
          3.1412e+07
          3.1412e+09

or rounding and padding the numbers with zeros

              314200
            31420000
          3142000000

The %w.dg, d>0, format assumes you do not want either of those solutions.
If you wanted the %e format, you can use the %e format at the outset.
We thought about implementing the round-and-pad solution, but came to the 
conclusion that researchers don't want that.  As long as digits are 
going to be displayed, one might as well put the actual digit in each 
position.

If there is an interest in the round-and-pad solution, we would be willing to
implement a %G format to go along with %g.
------------------------------------------------------------------------------

-- Bill
[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/



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