Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: precision Problem taking string from double var
From
<[email protected]>
To
<[email protected]>
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/