和stata数据存储和计算时的精度有关,在stata中用 == 运算符必须非常小心。
Although you may store your numeric variables as byte, int, long, float, or double, Stata converts all numbers to double before performing any calculations. Consequently, difficulties can arise in comparing numbers that have no finite binary representations.
For example, if the variable x is stored as a float and contains the value 1.1 (a repeating "decimal" in binary), the expression x==1.1 will evaluate to false because the literal 1.1 is the double representation of 1.1, which is different from the float representation stored in x. (They differ by 2.384 x 10^(-8).) The expression x==float(1.1) will evaluate to true because the float() function converts the literal 1.1 to its float representation before it is compared with x. (See [U] 13.10 Precision and problems therein for more information.)
在你的数据中high的存储类型应该是float?
第二种方法可行。或用gen uphitday=1 if high==float(round(preclose*1.1,.01))。此时两种方法的结果应该一样。
[此贴子已经被作者于2009-5-21 11:31:54编辑过]