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

st: observation about float()


From   VISINTAINER PAUL <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: observation about float()
Date   Wed, 25 Sep 2002 14:33:28 -0400

I have an interesting problem (or not) about float().  

I have a small program to categorize a continuous variable into quartiles,
and then assigns obs within each quartile the median of the quartile range.

The commands are:

xtile varx=var, nq(4)
sort varx
  forvalues num=1/4 {
      sum var if varx==`num', de
      replace varx=r(p50) if varx==`num'
}

The median for the first quartile (Q1) was 1.43.  When I tried to list the
observations in the first quartile, there were no observations.

	.list if varx==float(1.43)
	.(no observations)

In looking at the data editor, the assigned values for Q1 were 1.4300001
(varx is stored as a float).  Using -recast- and changing the storage to a
double didn't seem to work.

If I enter by hand the value "1.43" using the data editor as the median for
the first observation and then type 
	
	.list if varx==float(1.43)
	.(output for one observation)

The hand-entered value is listed as 1.4299999, while all others are
1.4300001

It seems that I can get float() to work on all observations with the
following code:

	.gen x=varx*100
	.gen vary=x/100

	.list if vary==float(1.43)
	.(output for all observations)

In this case, the value of "varx" is 1.4300001, whereas after the
conversion, the value of "vary" is 1.4299999.

It appears that float() is sensitive to the direction of the error.  My
question is whether this is expected behavior of float() and is there a
better way for dealing with these types of values

thanks
Paul Visintainer


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