楼主: loading.
1452 6

[数据管理求助] 变量的数据格式问题 [推广有奖]

  • 0关注
  • 0粉丝

初中生

47%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
39 点
帖子
4
精华
0
在线时间
27 小时
注册时间
2014-10-27
最后登录
2016-12-26

楼主
loading. 发表于 2014-10-27 16:25:48 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
现有变量x,数据为float型,format为numeric

其中一个观测值的x为9.2,输入后自动存储为9.1999998。

并且,在使用语句诸如 drop if x==9.2 时,选取不到该观测值;
drop if x <9.2 也会把该观测值drop掉。
看来是真的把该观测值的x作为9.1999998处理了。

请问大家,该怎么解决呢?
谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:数据格式 numeric format float FORMA

沙发
ermutuxia 发表于 2014-10-28 11:28:34
format x %10.1f
已有 1 人评分论坛币 学术水平 热心指数 收起 理由
SpencerMeng + 20 + 1 + 1 精彩帖子

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

藤椅
loading. 发表于 2014-10-29 09:17:48
ermutuxia 发表于 2014-10-28 11:28
format x %10.1f
非常感谢解答!
但是,使用该命令后,还是没能解决,可以再帮我看看吗

板凳
loading. 发表于 2014-10-29 09:24:01
format x %10.1f
执行后的数据格式是这样的。==, > 等符号还是存在识别问题

dsw.zip
下载链接: https://bbs.pinggu.org/a-1660514.html

336 Bytes

本附件包括:

  • dsw.dta

报纸
ermutuxia 发表于 2014-10-30 10:23:32
gen x_3=string(x,"%10.1f")
browse if x_3=="9.2"

地板
ermutuxia 发表于 2014-10-30 10:48:16
capture drop x_4
gen double x_4=real(string(x,"%10.1f"))

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.

    One solution is to type list if x==float(.1).  The float() function rounds its argument to float accuracy; see [D] functions.  The other alternative would be store your
    data as double, but this is probably a waste of memory.  Few people have data that is accurate to 1 part in 10 to the 7th.  Among the exceptions are banks, who keep
    records accurate to the penny on amounts of billions of dollars.  If you are dealing with such financial data, store your dollar amounts as doubles.

7
loading. 发表于 2014-11-20 17:12:02
ermutuxia 发表于 2014-10-30 10:48
capture drop x_4
gen double x_4=real(string(x,"%10.1f"))
我忘记回复了。
多谢前辈指点,受教了!

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

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