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: precision Problem taking string from double var
From
<[email protected]>
To
<[email protected]>
Subject
st: precision Problem taking string from double var
Date
Fri, 29 Oct 2010 12:28:31 +0200
Hi,
yesterday I ran into a severe error caused by some precision(?) problem with a double var.
I know what happened but not how it happened and I'm wondering how to avoid this in future.
I use record linkage software which creates Stata output files. The linkage score is stored in a double var.
I don't need that precision (two decimal places are enough, but I can't change this)
I use a Stata do-File to export the Stata output files to fixed format text files.
The files are given to a database for further processing.
The linkage score must be XX.XX (eg. 45.34) in the text files.
I use string functions to take the data out of the linkage score var "quality":
gen str5 linkage_score = substr(string(quality),1,2) + "." + substr(string(quality),4,2)
Now I found that in one case "45.0000037" the last function produces ""
One can see that ".0000" is o.k. but ".00000" is not.
. di substr(string(45.0000037),4,2)
. di substr(string(45.000037),4,2)
00
This rearranged the var positions in the output files causing a database error
I have huge record linkage numbers so this is likely to happen again. How can I avoid that?
Stefan Gawrich
Dillenburg
Germany
*
* 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/