st: Keeping trailing zeros when formatting a decimal

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

st: Keeping trailing zeros when formatting a decimal

mk-6
I would be very grateful for advice on the following basic formatting
questions...

To store a number as a string with a format showing 2 significant
figures, I do the following, for example:
di "`=string(-0.000029, "%9.2g")'"

If the second significant figure is a zero, how can I make sure this is
still displayed?
The following produces:
. di "`=string(-0.0000201, "%9.2g")'"
-.00002
when I want it to display "-0.000020"

Also, how can I make sure it displays the zero before the decimal point?

Also, why does
. di "`=string(-0.000029, "%9.1g")'"
-.000029
not show only 1 significant figure?

Many thanks for your help.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: AW: Keeping trailing zeros when formatting a decimal

Martin Weiss-5

<>

http://www.stata.com/support/faqs/data/leading0.html


http://www.stata.com/support/faqs/data/leadingzeros.html





HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Miranda Kim
Gesendet: Donnerstag, 1. Oktober 2009 13:33
An: [hidden email]
Betreff: st: Keeping trailing zeros when formatting a decimal

I would be very grateful for advice on the following basic formatting
questions...

To store a number as a string with a format showing 2 significant
figures, I do the following, for example:
di "`=string(-0.000029, "%9.2g")'"

If the second significant figure is a zero, how can I make sure this is
still displayed?
The following produces:
. di "`=string(-0.0000201, "%9.2g")'"
-.00002
when I want it to display "-0.000020"

Also, how can I make sure it displays the zero before the decimal point?

Also, why does
. di "`=string(-0.000029, "%9.1g")'"
-.000029
not show only 1 significant figure?

Many thanks for your help.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: AW: Keeping trailing zeros when formatting a decimal

Martin Weiss-5
In reply to this post by mk-6

<>

Most of your problems seem to be due to the fact that you are using "g"
instead of "f" in your formatting directives. See [U], 12.5 for more info.
Leading zeroes can be induced by inserting a zero after the percentage sign.

Also note that you do not need to use the -string()- function, as -display-
is able to apply a formatting directive on its own, as seen in the last row:


*************
di "`=string(-0.000029, "%9.2g")'"
di in red "`=string(-0.000029, "%09.2f")'"

di "`=string(-0.0000201, "%9.2g")'"
di in red "`=string(-0.0000201, "%7.6f")'"

di "`=string(-0.000029, "%9.1g")'"
di in red "`=string(-0.000029, "%09.1f")'"
di in red %09.1f -0.000029
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Miranda Kim
Gesendet: Donnerstag, 1. Oktober 2009 13:33
An: [hidden email]
Betreff: st: Keeping trailing zeros when formatting a decimal

I would be very grateful for advice on the following basic formatting
questions...

To store a number as a string with a format showing 2 significant
figures, I do the following, for example:
di "`=string(-0.000029, "%9.2g")'"

If the second significant figure is a zero, how can I make sure this is
still displayed?
The following produces:
. di "`=string(-0.0000201, "%9.2g")'"
-.00002
when I want it to display "-0.000020"

Also, how can I make sure it displays the zero before the decimal point?

Also, why does
. di "`=string(-0.000029, "%9.1g")'"
-.000029
not show only 1 significant figure?

Many thanks for your help.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: AW: Keeping trailing zeros when formatting a decimal

mk-6
For the leading zero issue, I want it to display say "-0.22" rather than
"-.22", and putting a 0 after the % doesn't seem to work:
. display %09.2g 0.5259
      .53
but I used:
subinstr(string(-0.22, "%9.2g"), ".", "0.",.)
which does the job.
However I'm still stuck for the trailing zeros...
I use "g" rather than "f" because I am wanting to apply this to many
different scales of decimal numbers, whether it be 0.000026789 or
0.23897, and just want to keep 2 significant figures.
My little program goes as follows:

program def numformat, rclass
    args num
    if abs(`num') > 1 {
        return local num = string(round(`num', 0.01), "%9.2f")
    }
    if abs(`num') < 1 & abs(`num') >= 0.0001 {
        return local num = subinstr(string(`num', "%9.2g"), ".", "0.",.)
    }
    if abs(`num') < 0.0001 {
        return local num = "< 0.0001"
    }
end

Martin Weiss wrote:

> <>
>
> Most of your problems seem to be due to the fact that you are using "g"
> instead of "f" in your formatting directives. See [U], 12.5 for more info.
> Leading zeroes can be induced by inserting a zero after the percentage sign.
>
> Also note that you do not need to use the -string()- function, as -display-
> is able to apply a formatting directive on its own, as seen in the last row:
>
>
> *************
> di "`=string(-0.000029, "%9.2g")'"
> di in red "`=string(-0.000029, "%09.2f")'"
>
> di "`=string(-0.0000201, "%9.2g")'"
> di in red "`=string(-0.0000201, "%7.6f")'"
>
> di "`=string(-0.000029, "%9.1g")'"
> di in red "`=string(-0.000029, "%09.1f")'"
> di in red %09.1f -0.000029
> *************
>
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Miranda Kim
> Gesendet: Donnerstag, 1. Oktober 2009 13:33
> An: [hidden email]
> Betreff: st: Keeping trailing zeros when formatting a decimal
>
> I would be very grateful for advice on the following basic formatting
> questions...
>
> To store a number as a string with a format showing 2 significant
> figures, I do the following, for example:
> di "`=string(-0.000029, "%9.2g")'"
>
> If the second significant figure is a zero, how can I make sure this is
> still displayed?
> The following produces:
> . di "`=string(-0.0000201, "%9.2g")'"
> -.00002
> when I want it to display "-0.000020"
>
> Also, how can I make sure it displays the zero before the decimal point?
>
> Also, why does
> . di "`=string(-0.000029, "%9.1g")'"
> -.000029
> not show only 1 significant figure?
>
> Many thanks for your help.
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>  

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

AW: st: AW: Keeping trailing zeros when formatting a decimal

Martin Weiss-5

<>

" I want it to display say "-0.22" rather than
"-.22", and putting a 0 after the % doesn't seem to work:"


Use "f" instead of "g":


*************
display %3.2f 0.5259
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [hidden email]
[mailto:[hidden email]] Im Auftrag von Miranda Kim
Gesendet: Donnerstag, 1. Oktober 2009 14:55
An: [hidden email]
Betreff: Re: st: AW: Keeping trailing zeros when formatting a decimal

For the leading zero issue, I want it to display say "-0.22" rather than
"-.22", and putting a 0 after the % doesn't seem to work:
. display %09.2g 0.5259
      .53
but I used:
subinstr(string(-0.22, "%9.2g"), ".", "0.",.)
which does the job.
However I'm still stuck for the trailing zeros...
I use "g" rather than "f" because I am wanting to apply this to many
different scales of decimal numbers, whether it be 0.000026789 or
0.23897, and just want to keep 2 significant figures.
My little program goes as follows:

program def numformat, rclass
    args num
    if abs(`num') > 1 {
        return local num = string(round(`num', 0.01), "%9.2f")
    }
    if abs(`num') < 1 & abs(`num') >= 0.0001 {
        return local num = subinstr(string(`num', "%9.2g"), ".", "0.",.)
    }
    if abs(`num') < 0.0001 {
        return local num = "< 0.0001"
    }
end

Martin Weiss wrote:
> <>
>
> Most of your problems seem to be due to the fact that you are using "g"
> instead of "f" in your formatting directives. See [U], 12.5 for more info.
> Leading zeroes can be induced by inserting a zero after the percentage
sign.
>
> Also note that you do not need to use the -string()- function, as
-display-
> is able to apply a formatting directive on its own, as seen in the last
row:

>
>
> *************
> di "`=string(-0.000029, "%9.2g")'"
> di in red "`=string(-0.000029, "%09.2f")'"
>
> di "`=string(-0.0000201, "%9.2g")'"
> di in red "`=string(-0.0000201, "%7.6f")'"
>
> di "`=string(-0.000029, "%9.1g")'"
> di in red "`=string(-0.000029, "%09.1f")'"
> di in red %09.1f -0.000029
> *************
>
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Miranda Kim
> Gesendet: Donnerstag, 1. Oktober 2009 13:33
> An: [hidden email]
> Betreff: st: Keeping trailing zeros when formatting a decimal
>
> I would be very grateful for advice on the following basic formatting
> questions...
>
> To store a number as a string with a format showing 2 significant
> figures, I do the following, for example:
> di "`=string(-0.000029, "%9.2g")'"
>
> If the second significant figure is a zero, how can I make sure this is
> still displayed?
> The following produces:
> . di "`=string(-0.0000201, "%9.2g")'"
> -.00002
> when I want it to display "-0.000020"
>
> Also, how can I make sure it displays the zero before the decimal point?
>
> Also, why does
> . di "`=string(-0.000029, "%9.1g")'"
> -.000029
> not show only 1 significant figure?
>
> Many thanks for your help.
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>  

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: AW: st: AW: Keeping trailing zeros when formatting a decimal

mk-6
but I use "g" because I'm interested in "2 significant figures" not just 2 decimal places...

For example 0.00040234 I want displayed as 0.00040
0.0326 as 0.033 etc.


My little program goes as follows:

program def numformat, rclass
    args num
    if abs(`num') > 1 {
        return local num = string(round(`num', 0.01), "%9.2f")
    }
    if abs(`num') < 1 & abs(`num') >= 0.0001 {
        return local num = subinstr(string(`num', "%9.2g"), ".", "0.",.)
    }
    if abs(`num') < 0.0001 {
        return local num = "< 0.0001"
    }
end



Martin Weiss wrote:

> <>
>
> " I want it to display say "-0.22" rather than
> "-.22", and putting a 0 after the % doesn't seem to work:"
>
>
> Use "f" instead of "g":
>
>
> *************
> display %3.2f 0.5259
> *************
>
>
>
> HTH
> Martin
>
>
> -----Ursprüngliche Nachricht-----
> Von: [hidden email]
> [mailto:[hidden email]] Im Auftrag von Miranda Kim
> Gesendet: Donnerstag, 1. Oktober 2009 14:55
> An: [hidden email]
> Betreff: Re: st: AW: Keeping trailing zeros when formatting a decimal
>
> For the leading zero issue, I want it to display say "-0.22" rather than
> "-.22", and putting a 0 after the % doesn't seem to work:
> . display %09.2g 0.5259
>       .53
> but I used:
> subinstr(string(-0.22, "%9.2g"), ".", "0.",.)
> which does the job.
> However I'm still stuck for the trailing zeros...
> I use "g" rather than "f" because I am wanting to apply this to many
> different scales of decimal numbers, whether it be 0.000026789 or
> 0.23897, and just want to keep 2 significant figures.
> My little program goes as follows:
>
> program def numformat, rclass
>     args num
>     if abs(`num') > 1 {
>         return local num = string(round(`num', 0.01), "%9.2f")
>     }
>     if abs(`num') < 1 & abs(`num') >= 0.0001 {
>         return local num = subinstr(string(`num', "%9.2g"), ".", "0.",.)
>     }
>     if abs(`num') < 0.0001 {
>         return local num = "< 0.0001"
>     }
> end
>
> Martin Weiss wrote:
>  
>> <>
>>
>> Most of your problems seem to be due to the fact that you are using "g"
>> instead of "f" in your formatting directives. See [U], 12.5 for more info.
>> Leading zeroes can be induced by inserting a zero after the percentage
>>    
> sign.
>  
>> Also note that you do not need to use the -string()- function, as
>>    
> -display-
>  
>> is able to apply a formatting directive on its own, as seen in the last
>>    
> row:
>  
>> *************
>> di "`=string(-0.000029, "%9.2g")'"
>> di in red "`=string(-0.000029, "%09.2f")'"
>>
>> di "`=string(-0.0000201, "%9.2g")'"
>> di in red "`=string(-0.0000201, "%7.6f")'"
>>
>> di "`=string(-0.000029, "%9.1g")'"
>> di in red "`=string(-0.000029, "%09.1f")'"
>> di in red %09.1f -0.000029
>> *************
>>
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: [hidden email]
>> [mailto:[hidden email]] Im Auftrag von Miranda Kim
>> Gesendet: Donnerstag, 1. Oktober 2009 13:33
>> An: [hidden email]
>> Betreff: st: Keeping trailing zeros when formatting a decimal
>>
>> I would be very grateful for advice on the following basic formatting
>> questions...
>>
>> To store a number as a string with a format showing 2 significant
>> figures, I do the following, for example:
>> di "`=string(-0.000029, "%9.2g")'"
>>
>> If the second significant figure is a zero, how can I make sure this is
>> still displayed?
>> The following produces:
>> . di "`=string(-0.0000201, "%9.2g")'"
>> -.00002
>> when I want it to display "-0.000020"
>>
>> Also, how can I make sure it displays the zero before the decimal point?
>>
>> Also, why does
>> . di "`=string(-0.000029, "%9.1g")'"
>> -.000029
>> not show only 1 significant figure?
>>
>> Many thanks for your help.
>>
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/statalist/faq
>> *   http://www.ats.ucla.edu/stat/stata/
>>
>>
>>  
>>    
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>  

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: Keeping trailing zeros when formatting a decimal

Roy Wada
In reply to this post by mk-6
> Subject: st: Keeping trailing zeros when formatting a decimal

This is actually difficult to do. The concept of significant digits
was nonexistant in Stata until it was introduced by -outreg2-.
 
The following program will do the plus-1 significance, meaning it
adds one more than you asked for.
 
I was going to put it up on ssc last year but never got around to it.
 
Roy
 

autofmt, input(2.200) auto(2)
ret list
 
 
*! autofmt 0.9 by [hidden email]
* Aug2008
* getting the significant digits
program define autofmt, rclass
version 7.0
* valstr renamed as fmt
syntax, input(string) [auto(integer 3) less(integer 0) parse(string)]
* parse( ) takes only one character; " " is always included as a parse
if `"`parse'"'=="" {
        local parse " "
}
local rest `"`input'"'
local count 0
if "`rest'"~="" {
        * handles the possibility the first token is empty
        gettoken first rest: rest, parse("`parse'")
        local first=trim(`"`first'"')
        if `"`first'"'==`"`parse'"' {
                local count=`count'+1
                local input`count' ""
        }
        else {
                local count=`count'+1
                local input`count' `"`first'"'
        }
}
while "`rest'"~="" {
        gettoken first rest: rest, parse("`parse'")
        local first=trim(`"`first'"')
        if `"`first'"'~=`"`parse'"' {
                local count=`count'+1
                local input`count' `"`first'"'
        }
}

if `count'==0 {
        * input( ) was left empty
        exit
}

*** run as many times
forval num=1/`count' {
        * confirm a number
        capture confirm number `input`num''
        local rc=_rc
       
        * run if not missing and is a number
        if "`input`num''"~="." & "`input`num''"~="" & `rc'==0 {
                local times=0
                local left=0
               
                * integer checked by modified mod function
                if round((`input`num'' - int(`input`num'')),0.0000000001)==0 {
                        local whole=1
                }
                else {
                        local whole=0
                        * non-interger
                         if `input`num''<. {
                               
                                * digits that need to be moved if it were only decimals: take the ceiling of log 10 of absolute value of decimals
                                local times=abs(int(ln(abs(`input`num''-int(`input`num'')))/ln(10)-1))  
                               
                                * the whole number: take the ceiling of log 10 of absolute value
                                local left=int(ln(abs(`input`num''))/ln(10)+1)
                        }
                }
               
               
                * assign the fixed decimal values into aadec
                if `whole'==1 {
                        local aadec=0
                }
                else if .>`left' & `left'>0 {
                        * reduce the left by one if more than zero to accept one extra digit
                        if `left'<=`auto' {
                                local aadec=`auto'-`left'+1
                        }
                        else {
                                local aadec=0
                        }
                }
                else {
                        local aadec=`times'+`auto'-1
                }
               
                if "`less'"=="" {
                        * needs to between 0 and 11
                        if `aadec'<0 {
                                local aadec=0
                        }
                        *if `aadec'<11 {
                        if `aadec'<7 {
                                * use fixed
                                local fmt "`aadec'f"
                        }
                        else {
                                * use exponential
                                local fmt "`=`auto'-1'e"
                        }
                }
                else {
                        * needs to between 0 and 11
                        local aadec=`aadec'-`less'
                        if `aadec'<0 {
                                local aadec=0
                        }
                        *if `aadec'<10 {
                        if `aadec'<7 {
                                * use fixed
                                local fmt "`aadec'f"
                        }
                        else {
                                * use exponential
                                local fmt "`=`auto'-1'e"
                        }
                }
               
                * make it exponential if too big
                if `input`num''>1000000 & `input`num''<. {
                        local fmt "`=`auto'-0'e"                
                }
               
                * make it exponential if too negative (small)
                if `input`num''<-1000000 & `input`num''<. {
                        local fmt "`=`auto'-0'e"                
                }
               
                local fmt`num' `fmt'
                local aadec`num' `aadec'
               
               
                local output`num'=string(`input`num'',"%12.`fmt'")
               
                return scalar deci`num'=`aadec'
                return local fmt`num'="`fmt'"
                return local input`num'="`input`num''"
               
                return local output`num'=`"`output`num''"'
        }
        else {
                * it is a missing value, empty, or non-number
                local output`num'=trim(`"`input`num''"')
               
                return scalar deci`num'=.
                return local fmt`num'="."
                if "`input`num''"=="" {
                        * return a dot when empty
                        return local input`num'="."
                }
                else {
                        return local input`num'="`input`num''"
                }
               
                return local output`num'=`"`output`num''"'
        }
}
end

 
 
     
_________________________________________________________________
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: Keeping trailing zeros when formatting a decimal

Roy Wada
 <[hidden email]>
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0


It will handle multiple inputs afterall.

autofmt=2C input(2.200 2.2222 3.123456) auto(2)
=20
Roy
     =0A=
_________________________________________________________________=0A=
Bing=99  brings you maps=2C menus=2C and reviews organized in one place.   =
Try it now.=0A=
http://www.bing.com/search?q=3Drestaurants&form=3DMLOGEN&publ=3DWLHMTAG&cre=
a=3DTEXT_MLOGEN_Core_tagline_local_1x1=
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: RE: Keeping trailing zeros when formatting a decimal

Nick Cox
In reply to this post by mk-6
This generated a lively thread. (Oddly enough, although I still remember
teachers stressing the idea of sig.fig. -- as it was called where I grew
up -- in practice I always want to program display with either Stata's
defaults or a fixed number of decimal places.)

My one contribution is slightly oblique. If existing formats don't suit,
it seems a better strategy to drill down and try first principles.

1. Significant figures can be got from the fractional part of the base
10 logarithm of whatever it is.

. di round(10 * 10^mod(log10(.123456789), 1))
12

. di round(10 * 10^mod(log10(123456789), 1))
12

-- with different prefactors as desired.

2. Multiplying powers can be got from the integer part of same.

. di floor(log10(123456789))
8

. di floor(log10(.123456789))
-1

3. Logically it seems that's all the information you need to work out
leading and trailing zeros, except that if there's a negative sign you
have to strip it off first and put it back again.

I haven't tried to understand Roy Wada's program, which at heart should
be equivalent to this. No doubt the help file will document that it also
deals with complications that I have missed.

Nick
[hidden email]

Miranda Kim

I would be very grateful for advice on the following basic formatting
questions...

To store a number as a string with a format showing 2 significant
figures, I do the following, for example:
di "`=string(-0.000029, "%9.2g")'"

If the second significant figure is a zero, how can I make sure this is
still displayed?
The following produces:
. di "`=string(-0.0000201, "%9.2g")'"
-.00002
when I want it to display "-0.000020"

Also, how can I make sure it displays the zero before the decimal point?

Also, why does
. di "`=string(-0.000029, "%9.1g")'"
-.000029
not show only 1 significant figure?


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: Keeping trailing zeros when formatting a decimal

Roy Wada
 <[hidden email]>
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0


=20
log10 wasn't available back then. I am not sure floor( ) was available=2C e=
ither.
=20
At least that's my excuse.

In a way my codes are utterly basic=2C doing it from scratch from the princ=
iples=20
of high school mathematics.
=20
No doubt the codes can be shortened.

There is something about the negative number rounding in the wrong directio=
n=20
but I don't recall offhand.

Incidently=2C this is an example that doesn't work without a further adjust=
ment.
=20
. di round(10 * 10^mod(log10(0.0001)=2C 5))
100
=20
Roy
=20
=20
> This generated a lively thread. (Oddly enough=2C although I still remembe=
r
> teachers stressing the idea of sig.fig. -- as it was called where I grew
> up -- in practice I always want to program display with either Stata's
> defaults or a fixed number of decimal places.)=20
>=20
> My one contribution is slightly oblique. If existing formats don't suit=
=2C

> it seems a better strategy to drill down and try first principles.=20
>=20
> 1. Significant figures can be got from the fractional part of the base
> 10 logarithm of whatever it is.=20
>=20
> . di round(10 * 10^mod(log10(.123456789)=2C 1))
> 12
>=20
> . di round(10 * 10^mod(log10(123456789)=2C 1))
> 12
>=20
> -- with different prefactors as desired.=20
>=20
> 2. Multiplying powers can be got from the integer part of same.=20
>=20
> . di floor(log10(123456789))
> 8
>=20
> . di floor(log10(.123456789))
> -1
>=20
> 3. Logically it seems that's all the information you need to work out
> leading and trailing zeros=2C except that if there's a negative sign you
> have to strip it off first and put it back again.=20
>=20
> I haven't tried to understand Roy Wada's program=2C which at heart should
> be equivalent to this. No doubt the help file will document that it also
> deals with complications that I have missed.=20
>=20
> Nick=20
> [hidden email]      =0A=
_________________________________________________________________=0A=
Microsoft brings you a new way to search the web.  Try  Bing=99 now=0A=
http://www.bing.com?form=3DMFEHPG&publ=3DWLHMTAG&crea=3DTEXT_MFEHPG_Core_ta=
gline_try bing_1x1=
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: Keeping trailing zeros when formatting a decimal

Roy Wada
In reply to this post by Nick Cox
 <[hidden email]>
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0


=20
Here is a repost with something added:
=20
log10 wasn't available back then. I am not sure floor( ) was available=2C e=
ither.

At least that's my excuse.
=20
In a way my codes are utterly basic=2C doing it from scratch from the princ=
iples
of high school mathematics.

No doubt the codes can be shortened=2C but you need to count the whole numb=
ers=20
to the left of a decimal as a part of signficant digits.
=20
=20
=20
local input 123.12345000
local dec 5
=20
local decimals=3Dabs(int(log10(`input')))
local whole=3Dint(log10(`input'))
if `whole'<=3D`dec' {
  local format=3D`dec'-`whole'
}
else {
  local format=3D0
}
di "`=3Dstring(`input'=2C"%12.`format'f")'"
=20
=20
=20
Incidently this is an example that doesn't work without a further adjustmen=
t.

. di round(10 * 10^mod(log10(0.0001)=3D2C 5))
100

Roy

=20
> This generated a lively thread. (Oddly enough=2C although I still remembe=
r
> teachers stressing the idea of sig.fig. -- as it was called where I grew
> up -- in practice I always want to program display with either Stata's
> defaults or a fixed number of decimal places.)
>
> My one contribution is slightly oblique. If existing formats don't suit=
=2C

> it seems a better strategy to drill down and try first principles.
>
> 1. Significant figures can be got from the fractional part of the base
> 10 logarithm of whatever it is.
>
> . di round(10 * 10^mod(log10(.123456789)=2C 1))
> 12
>
> . di round(10 * 10^mod(log10(123456789)=2C 1))
> 12
>
> -- with different prefactors as desired.
>
> 2. Multiplying powers can be got from the integer part of same.
>
> . di floor(log10(123456789))
> 8
>
> . di floor(log10(.123456789))
> -1
>
> 3. Logically it seems that's all the information you need to work out
> leading and trailing zeros=2C except that if there's a negative sign you
> have to strip it off first and put it back again.
>
> I haven't tried to understand Roy Wada's program=2C which at heart should
> be equivalent to this. No doubt the help file will document that it also
> deals with complications that I have missed.
>
> Nick
> [hidden email]    =0A=
_________________________________________________________________=0A=
Bing=99  brings you maps=2C menus=2C and reviews organized in one place.   =
Try it now.=0A=
http://www.bing.com/search?q=3Drestaurants&form=3DMLOGEN&publ=3DWLHMTAG&cre=
a=3DTEXT_MLOGEN_Core_tagline_local_1x1=
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: Keeping trailing zeros when formatting a decimal

Roy Wada-2
Sorry about the mess. The server apparently doesn't like Hotmail.

This is a repost using Gmail:

log10 wasn't available back then. I am not sure floor( ) was
available, either. At least that's
my excuse. In a way my codes are utterly basic doing it from scratch
from the principles of
high school mathematics.

The codes can be shortened but you need to count the whole numbers to
the left of the decimal
point as a part of signficant digits.


local input 123.12345000
local dec 5

local decimals=abs(int(log10(`input')))
local whole=int(log10(`input'))
if `whole'<=`dec' {
 local format=`dec'-`whole'
}
else {
 local format=0
}

di "`=string(`input',"%12.`format'fc")'"


Incidently this is an example that doesn't work without a further adjustment.

. di round(10 * 10^mod(log10(.000001), 5))
100000

Roy



Nick said:

This generated a lively thread. (Oddly enough=2C although I still remember
teachers stressing the idea of sig.fig. -- as it was called where I grew
up -- in practice I always want to program display with either Stata's
defaults or a fixed number of decimal places.)

My one contribution is slightly oblique. If existing formats don't suit
it seems a better strategy to drill down and try first principles.

1. Significant figures can be got from the fractional part of the base
10 logarithm of whatever it is.

. di round(10 * 10^mod(log10(.123456789)=2C 1))
12

. di round(10 * 10^mod(log10(123456789)=2C 1))
12

-- with different prefactors as desired.

2. Multiplying powers can be got from the integer part of same.

. di floor(log10(123456789))
8

. di floor(log10(.123456789))
-1

3. Logically it seems that's all the information you need to work out
leading and trailing zeros=2C except that if there's a negative sign you
have to strip it off first and put it back again.

I haven't tried to understand Roy Wada's program=2C which at heart should
be equivalent to this. No doubt the help file will document that it also
deals with complications that I have missed.

Nick
[hidden email]
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: Keeping trailing zeros when formatting a decimal

Nick Cox
Thanks for your comments. I look forward to seeing documentation of your
program.

Your answer raises a tiny historical question. Looking at various
manuals I see that -log10()- was added in Stata 4 and -floor()- was
added in Stata 8, so neither can be regarded as recent additions to
Stata.

Nick
[hidden email]

Roy Wada

log10 wasn't available back then. I am not sure floor( ) was
available, either. At least that's
my excuse. In a way my codes are utterly basic doing it from scratch
from the principles of
high school mathematics.

The codes can be shortened but you need to count the whole numbers to
the left of the decimal
point as a part of signficant digits.


local input 123.12345000
local dec 5

local decimals=abs(int(log10(`input')))
local whole=int(log10(`input'))
if `whole'<=`dec' {
 local format=`dec'-`whole'
}
else {
 local format=0
}

di "`=string(`input',"%12.`format'fc")'"

Incidently this is an example that doesn't work without a further
adjustment.

. di round(10 * 10^mod(log10(.000001), 5))
100000

Nick said:

This generated a lively thread. (Oddly enough=2C although I still
remember
teachers stressing the idea of sig.fig. -- as it was called where I grew
up -- in practice I always want to program display with either Stata's
defaults or a fixed number of decimal places.)

My one contribution is slightly oblique. If existing formats don't suit
it seems a better strategy to drill down and try first principles.

1. Significant figures can be got from the fractional part of the base
10 logarithm of whatever it is.

. di round(10 * 10^mod(log10(.123456789)=2C 1))
12

. di round(10 * 10^mod(log10(123456789)=2C 1))
12

-- with different prefactors as desired.

2. Multiplying powers can be got from the integer part of same.

. di floor(log10(123456789))
8

. di floor(log10(.123456789))
-1

3. Logically it seems that's all the information you need to work out
leading and trailing zeros=2C except that if there's a negative sign you
have to strip it off first and put it back again.

I haven't tried to understand Roy Wada's program=2C which at heart
should
be equivalent to this. No doubt the help file will document that it also
deals with complications that I have missed.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: Keeping trailing zeros when formatting a decimal

Roy Wada
 <[hidden email]>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0


It looks like you are right about that.
=20
All I remember is that there was a brouhaha about Stata not providing=20
non-natural logs. It looks like that discussion was actually about bases=20
other than natural or base 10=2C which was available.
=20
So the moral of the story is that you can always do it from scratch=20
but usually don't have to.
=20
Roy
=20
=20
>
> Your answer raises a tiny historical question. Looking at various
> manuals I see that -log10()- was added in Stata 4 and -floor()- was
> added in Stata 8=2C so neither can be regarded as recent additions to
> Stata.
>
> Nick
> [hidden email]
>    =0A=
_________________________________________________________________=0A=
Insert movie times and more without leaving Hotmail=AE.=0A=
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=3DTXT_TAGLM_WL_HM_Tut=
orial_QuickAdd_062009=
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: Adjusting Range of Graph

Sungbok Lee
In reply to this post by Roy Wada
Hi all,

Do you have a screte way to narrow down a graph less than the min or max
range of the axis? It's a scatter over time. But the initial value is too
large to recongize the last value which is close to zero.

Sungbok Lee

 

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

st: RE: Adjusting Range of Graph

Nick Cox
I don't know what "screte" means here, but you should use -if- or -in-
or equivalent restrictions to omit values.

Nick
[hidden email]

javanfish (a.k.a. Sungbok Lee)

Do you have a screte way to narrow down a graph less than the min or max

range of the axis? It's a scatter over time. But the initial value is
too
large to recongize the last value which is close to zero.


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: Adjusting Range of Graph

Sungbok Lee
--------------------------------------------------
From: "Nick Cox" <[hidden email]>
Sent: Thursday, October 08, 2009 11:11 AM
To: <[hidden email]>
Subject: st: RE: Adjusting Range of Graph

Thanks, Nick.

I did that, but as you know, -if- in graph is just about filtering the
values.
What I want is to cut off the graph as I set the range of y axis which may
be not supported by STATA.com
Sometimes, we need to magnify the graph as we want to see. It's a way to cut
off the range.

Further, it will be better for STATA to support alpha(transparency) where
overlapping twoway graph.

Sungbok Lee.

> I don't know what "screte" means here, but you should use -if- or -in-
> or equivalent restrictions to omit values.
>
> Nick
> [hidden email]
>
> javanfish (a.k.a. Sungbok Lee)
>
> Do you have a screte way to narrow down a graph less than the min or max
>
> range of the axis? It's a scatter over time. But the initial value is
> too
> large to recongize the last value which is close to zero.
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: Adjusting Range of Graph

Nick Cox
Stata does not support transparency. I wish it did so that I could play
with it. At the same time, I have the niggling suspicion that
transparency is greatly overrated. If you have so much data that your
data points overlap greatly, your main need is not to change the graph
format but to supplement the graph with suitable summaries, typically
smooths of various kinds.

It may be that supporting transparency on all platforms that Stata
supports is problematic.

However ---

I don't see what that's got to do with adjusting range, and -if- isn't
the answer I have to say that I evidently don't understand your original
question. Perhaps you want some kind of zooming. Basically, anything
important is documented, so if it's not evident it doesn't exist.

Nick
[hidden email]

javanfish (Sungbok Lee)

Thanks, Nick.

I did that, but as you know, -if- in graph is just about filtering the
values.
What I want is to cut off the graph as I set the range of y axis which
may
be not supported by STATA.com
Sometimes, we need to magnify the graph as we want to see. It's a way to
cut
off the range.

Further, it will be better for STATA to support alpha(transparency)
where
overlapping twoway graph.

Nick Cox

> I don't know what "screte" means here, but you should use -if- or -in-
> or equivalent restrictions to omit values.

javanfish (a.k.a. Sungbok Lee)
>
> Do you have a screte way to narrow down a graph less than the min or
max
>
> range of the axis? It's a scatter over time. But the initial value is
> too
> large to recongize the last value which is close to zero.
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/