Hi Ben,
Try :
replace var1 = 9 if var == float(1.1)
See -help float- for more info.
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: [email protected] [mailto:[email protected]] On Behalf Of Ben Zipperer
Sent: Thursday, October 30, 2008 4:01 PM
To: [email protected]
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?
Thanks for your help,
Ben
. clear
. mata st_addobs(1)
. 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
(0 real changes made)
. replace var1 = 9 if var2==1
(1 real change made)
*
* 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/