|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: real vs destring
On Apr 4, 2008, at 9:10 AM, Nicholas Harrigan wrote:
I am trying to recode a variable containing large numbers which are
currently held as strings.
I am wondering why real and destring give different results
<snip>
gen new_var = real(old_var)
gen new_var2 = old_var
destring new_var2, replace
This is because your values (e.g., 5560001090 and 5560001108) are too
large to be stored accurately as floats. -destring- is smart enough
to recognize this, and, I believe, notifies you when it creates a
variable as a double. You would get the same result if you used
gen double new_var = real(old_var)
instead (see [U] 12.2.2 Numeric storage types for more information).
Does this mean I should use always use destring in my coding
instead of real?
Not a bad idea, since -destring- will balk if the conversion involves
a loss of information. However, you should always give some thought
as to how you are storing your data and its implications for what you
are doing with them.
-- Phil
*
* 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/