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

st: RE: data representation


From   "Frank de Libero" <[email protected]>
To   <[email protected]>
Subject   st: RE: data representation
Date   Thu, 26 Dec 2002 22:05:57 -0800

The -float()- function rounds its argument to floating place accuracy, but
doesn't change how it's stored since that's integral to its binary
representation. In short, what you want is

assert z_coef>=float(3.05) & z_coef<=float(5.55)
Not commands like
replace z_coef = float(5.55) if year == 1991
because, as assert told you, -float()- didn't (and can't) change how the
number is stored.
..Frank




-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Katsuhide Isa
Sent: Thursday, December 26, 2002 5:22 PM
To: [email protected]
Subject: st: data representation

Hello,

I'm annoyed by the following problem.
I issued the following commands.

----------
generate z_coef = .
replace z_coef = 5.10 if year == 1989
replace z_coef = 5.40 if year == 1990
replace z_coef = 5.55 if year == 1991 /*max*/
replace z_coef = 5.15 if year == 1992
replace z_coef = 4.00 if year == 1993
replace z_coef = 3.05 if year == 1994 /*min*/
replace z_coef = 3.78 if year == 1995
replace z_coef = 4.00 if year == 1996
replace z_coef = 3.50 if year == 1997
replace z_coef = 4.10 if year == 1998
replace z_coef = 4.10 if year == 1999
replace z_coef = 4.10 if year == 2000
replace z_coef = 4.10 if year == 2001

assert z_coef>=3.05 & z_coef<=5.55

----------
Then, Stata returned this error message:

7088 contradictions in 39384 observations
assertion is false
r(9);

Given the above simple commands, this message is
apparently hard to understand.
So, I checked the 'z_coef' variable in Stata editor.
Then, I found 5.55 actually stored as 5.5500002 and
so on (Of the above figures, 3.05,3.78 and 4.00 are
shown exactly as they are supposed to be)

According to '[U] 16.10 Precision and problems therein.',
this is because 'Stata stores numbers internally in
binary'.
I understand this logic, but this manner is sometimes
inconvenient, especially when one wants to perform
commands like -assertion-.

Though the manual recommends the use of float( ), like,
  replace z_coef = float(5.55) if year == 1991
this mehod doesn't seem to deliver the goods; the
results are the same.
Though this phenomenon may not affect the data
analysis, it makes me somehow embarrassed, given the
above error message against -assertion-.

Is there any other way to deal with this problem?
Any suggestions welcome.
Thanks in advance.

K.I.

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



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