Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: precision Problem taking string from double var


From   <Stefan.Gawrich@hlpug.hessen.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: precision Problem taking string from double var
Date   Fri, 29 Oct 2010 14:23:06 +0200

Thanks Maarten and Nick!

Creating an integer var is not so good in this special case because these files are huge already.
Formatting the string output "%4.2" works fine. 

Doubles have 16 digits precision but without -format- option the -string- function does not follow that.


Example:


clear
set obs 2
gen double x = 45.0000049 if _n == 1
replace x = 45.0000050 if _n == 2
gen string = string(x)
gen str2 y =substr(string(x),4,2)
gen str2 z =substr(string(x, "%4.2f"),4,2)
br



Thanks again

Stefan 






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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index