# st: Keeping trailing zeros when formatting a decimal

18 messages
Open this post in threaded view
|

## 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/
Open this post in threaded view
|

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

 <> http://www.stata.com/support/faqs/data/leading0.htmlhttp://www.stata.com/support/faqs/data/leadingzeros.htmlHTH 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/
Open this post in threaded view
|

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

 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/
Open this post in threaded view
|

## 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/
Open this post in threaded view
|

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

 <> " 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/
Open this post in threaded view
|

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

 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/
Open this post in threaded view
|

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

Open this post in threaded view
|

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

 <[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/
Open this post in threaded view
|

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

 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/
Open this post in threaded view
|

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

 <[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/
Open this post in threaded view
|

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

 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/
Open this post in threaded view
|

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

 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/
Open this post in threaded view
|

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

Open this post in threaded view
|

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

 <[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/
Open this post in threaded view
|

## st: Adjusting Range of Graph

 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/
Open this post in threaded view
|

## st: RE: Adjusting Range of Graph

 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/