Dear Statalist users,
I have come across something I do not quite understand: why does the if qualifier work for integer values of a vriable, but not if the values are decimals?
See the following example (I have Stata 12 SE):
sysuse auto
* 1.
gen myvar1=0
replace myvar1=1 if turn==40
* This works fine: 6 real changes made
* 2.
replace turn = turn/100
gen myvar2=0
replace myvar2=1 if turn==0.40
* This does not: 0 real changes made
* 3.
replace myvar2=1 if turn>0.39999999 & turn<.40000001
* This again works: 6 real changes made
Why does the second example not work? And is there a nicer workaround than what I did in the third example?
Looking forward to your comments!
Isabel
I have come across something I do not quite understand: why does the if qualifier work for integer values of a vriable, but not if the values are decimals?
See the following example (I have Stata 12 SE):
sysuse auto
* 1.
gen myvar1=0
replace myvar1=1 if turn==40
* This works fine: 6 real changes made
* 2.
replace turn = turn/100
gen myvar2=0
replace myvar2=1 if turn==0.40
* This does not: 0 real changes made
* 3.
replace myvar2=1 if turn>0.39999999 & turn<.40000001
* This again works: 6 real changes made
Why does the second example not work? And is there a nicer workaround than what I did in the third example?
Looking forward to your comments!
Isabel
Comment