# st: RE: Problem with replace if - test condition works only for some values of test variable

 From "Martin Weiss" To Subject st: RE: Problem with replace if - test condition works only for some values of test variable Date Fri, 24 Oct 2008 09:15:10 +0200

```"Start with any dataset open": Not quite true. You must -set obs 101- to run

Also look at http://www.stata.com/support/faqs/data/float.html

HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Naunihal Singh
Sent: Friday, October 24, 2008 12:32 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: Problem with replace if - test condition works only for some
values of test variable

Please, indulge me. I'm sure I've overlooked something basic, but
replace if is working only for certain values of the test variable and
not for others.

Here is the code fragment that replicates my problem:

ge y=.
generate x= (_n/100)-0.01 in 1/101
replace y=1 if x==0
replace y=1 if x==.01
replace y=1 if x==.25
replace y=1 if x==.26
replace y=1 if x==.5
replace y=1 if x==.51
replace y=1 if x==.75
replace y=1 if x==.76
replace y=1 if x==1
replace y=1 if x==.99

I'm able to make assignments to y only when x equals 0, .25, .5, .75,
and 1 but for no other value. This is the output I get:

. replace y=1 if x==.5

. replace y=1 if x==.51

Why does this happen and how do I fix it? x is a float, so it should
have enough precision for the test condition. And if the test can
recognize .25 it should be able to recognize .26.

Thanks

N
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```