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

st: Re: Why does Stata do it wrong?


From   "Michael Blasnik" <michael.blasnik@verizon.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: Why does Stata do it wrong?
Date   Mon, 9 Jun 2003 09:50:26 -0400

This is a common listserv item -- the problem is one of precision.  Yes,
Stata does store numbers in a different format -- different from decimal -- 
it's called binary and it's what computers use ;).

If you want to hold 9+ digit numbers accurately they must generated as
doubles (or sometimes longs are long enough).  try:  gen double id = .....

Given how often this question comes up on the list, I feel that perhaps
StataCorp should consider shipping Stata with double as the default variable
type instead of float.

Michael Blasnik
michael.blasnik@verizon.net


----- Original Message ----- 
From: "Tesfayi Gebre" <tesfaron@yahoo.com>
To: <statalist@hsphsun2.harvard.edu>
Sent: Monday, June 09, 2003 8:45 AM
Subject: st: Why does Stata do it wrong?


> Dear Statlister,
>
> I want to generate a single unique id to merge files
> by using variables: var1 (F1) var2 (F3) var3 (F4) and
> var4 (F2), where F shows the integer width (f format).
> So, I used
>
> gen id = var1*10^9 + var2*10^6 + var3*10^2 + var4
>
> This is the output from stata and the true id (as it
> should be) for the following
> example:
>
> var1   var2   var3  var4   id (stata)   id (true)
> 1      2      3452   1     1005452032 1002345201
> 1      121    34     10    1121033984 1121003410
> 2      23     156    2     2023155968 2023015602
> 2      45     3      2     2045003008 2045000302
> 3      6      4      3     3006003968 3006000403
> 3      70     8      5     3070008064 3070000805
>


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