# st: RE: trouble with replace and decimals

 From Howard Lempel To "statalist@hsphsun2.harvard.edu" Subject st: RE: trouble with replace and decimals Date Thu, 30 Oct 2008 16:07:55 -0400

```Hi Ben,

Try :

replace var1 = 9 if var == float(1.1)

Basically, var3 is a float and therefore stores the float representation of 1.1, which is not exactly 1.1.  The -float- function converts 1.1 to the float representation of 1.1 before comparing it to the value stored in var3.

Hope this helps.
Howie

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ben Zipperer
Sent: Thursday, October 30, 2008 4:01 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: trouble with replace and decimals

I am having trouble with the --replace-- command. Below is a simple
example. My intention is to make var1=9 for all observations with
var3==1.1. What is wrong with my code?

Ben

. clear

. gen var1 = 0

. gen var2 = 1

. gen var3 = 1.1

. sum

Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
var1 |         1           0           .          0          0
var2 |         1           1           .          1          1
var3 |         1         1.1           .        1.1        1.1

. replace var1 = 9 if var3==1.1

. replace var1 = 9 if var2==1

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