Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: transform string to numeric vars


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: transform string to numeric vars
Date   Tue, 3 Jun 2003 14:08:14 -0400

The problem is one of the stored precision of numeric variable types -- a
common topic on the list.  You are generating a float var and trying to have
it store 9 digits accurately -- you need to generate a double or long (not
the default float).     I haven't checked, but I would guess that destring
checks to see what numeric type is needed to maintain all digits.

Michael Blasnik
michael.blasnik@verizon.net

----- Original Message ----- 
From: "Harald Seider" <harald.seider@wiwi.uni-augsburg.de>
To: <statalist@hsphsun2.harvard.edu>
Sent: Tuesday, June 03, 2003 1:51 PM
Subject: st: transform string to numeric vars


> Dear List,
>
> I came across a weird problem with STATAs destring command (I am using
> Stata8 on a XP environment).
>
> My intention was to transfer a string variable "hospid" into a numeric
> variable (regardless the usefulness of such an action).
> So far I understand there are two ways to proceed: real(var) and destring
> var. I would have expected that both commands will give identical results.
> Unfortunately they don't.
>
> So I compared both commands:
>
>   'generate hospidold = real(hospid)' and
> 'destring hospid, generate(hospidnew)'
>
> When comparing hospidold and hospidnew I get slightly different results.
>
> Example:
>
> variables:      hospid(string)          hospidold(float)
> hospidnew(long)
> content:        106010735               106010736               106010735
>
> Therefore   'generate hospidold = real(hospid)' gives wrong results.
>
> Has anybody faced this problem before? Is it a well non issue (I haven't
> found anything on the list so far).
>
> Best
> Harald Seider
>
>
>
> ************************************************
> Dipl. oec. Harald Seider
> Department of Economics II
> Universitätsstraße 16
> D-86159 Augsburg
>
> Tel: +49-821-598 4208
> Fax: +49-821-598 4232
>
> E-Mail: harald.seider@wiwi.uni-augsburg.de


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



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