全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
4163 3
2015-06-04
stata版本13.1
主要是在清洗监测数据时遇到的麻烦,目的是将一个变量中的1.44替换为144。命令为
replace var=144  if var==1.44,
但是返回结果是0替换。在数据表格中该列1.44这个值却是存在的。

后来经过测试 if var == 后面是整数的话,可以实现替换,如果是带小数位数的,替换全部失败。
使用gen if 来生成新变量也是同样的问题。
向各位请教一下是怎么回事,有什么好办法解决不?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-6-4 19:44:18
补充一下,小数位数只有1位似乎也能替换,但是两位就不行了
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-6-4 19:50:51
和精确度有关,1.44为浮点数,请参考:

“Stata stores numbers in binary, and this has a second effect on numbers less than 1.  1/10 has no perfect binary representation just as 1/11 has no perfect decimal representation.  In float, .1 is stored as .10000000149011612.  Note that there are 7 digits of accuracy, just as with numbers larger than 1.  Stata, however, performs all calculations in double precision.  If you were to store 0.1 in a float called x and then ask, say, "list if x==.1", there would be nothing in the list.  The .1 that you just typed was converted to double, with 16 digits of accuracy (.100000000000000014...), and that number is never equal to 0.1 stored with float accuracy.”

可能的解决方案:replace var=144  if var==float(1.44)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-6-4 20:01:11
成功解决问题了,谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群