That's a tough one.
First, I tried using
gen double y = real(x)
(Variables with type -double- have, well, double precision)
However, as the following example can show, this is not enough to
maintain ALL the precision.
1) make the data
input str20 x
348080.2688552010
end
2)
gen a=real(x)
gen double b=real(x)
destring x, gen(c)
browse
3) Alternative (a) is pretty bad.
(b) and (c) give 3.4808026885520e+05, which is pretty close.
If that is not enough, I can't help.
By the way, you can try importing the data specifying it as -double-.
The exact way to do this depends on whether you use -insheet-,
-infile-, etc. Search the help of the command you used for a -double-
option or something like that.
Sergio
On 11/11/05, Ronnie Babigumira <[email protected]> wrote:
> Dear all
> I have scanned some of the previous posts on this subject but I am not
> making any headway.
>
> I have text file with two variables whose contents are 16 digit numbers
> of the form
>
> x
> 348080.2688552010
>
> I would like to import the data into stata whilst maintainig the
> precision. Here is what I have done. I import the variables as strings
> and that works. However, the next challenge is that they need to be used
> as numeric variables (this is the hair loss part). I have tried
>
> gen y = real(x)
> destring x, gen(y)
>
> Both dont have an option to specify the format. Trying to format the
> generated variables also wont help since format y %9.11f gives me the
> dreaded red lines and blue lines
>
> invalid %format
> r(120);
>
> So my question is how can I change x from string to numeric whilst
> maintaining the precision. Or even better, how best can I import this
> into stata as a numeric variable without loss of precision.
>
> Ronnie
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/