楼主: mithanan
4244 3

[数据管理求助] Stata if语句对小数的判别 [推广有奖]

  • 0关注
  • 0粉丝

小学生

92%

还不是VIP/贵宾

-

威望
0
论坛币
1540 个
通用积分
0.8500
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
15162 点
帖子
5
精华
0
在线时间
15 小时
注册时间
2009-11-26
最后登录
2025-2-13

楼主
mithanan 发表于 2015-6-4 19:40:34 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
stata版本13.1
主要是在清洗监测数据时遇到的麻烦,目的是将一个变量中的1.44替换为144。命令为
replace var=144  if var==1.44,
但是返回结果是0替换。在数据表格中该列1.44这个值却是存在的。

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

二维码

扫码加我 拉你入群

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

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

关键词:Stata tata replace place 数据表格 replace 清洗

沙发
mithanan 发表于 2015-6-4 19:44:18
补充一下,小数位数只有1位似乎也能替换,但是两位就不行了

藤椅
rudi 发表于 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)
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
SpencerMeng + 20 + 1 + 1 精彩帖子

总评分: 论坛币 + 20  学术水平 + 1  热心指数 + 1   查看全部评分

板凳
mithanan 发表于 2015-6-4 20:01:11
成功解决问题了,谢谢

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-31 03:13