楼主: shihongjun118
1070 2

[数据管理求助] stata通过运算生成新变量后,新变量的值不仅出现了错误,小数点后面的数字不见了? [推广有奖]

  • 1关注
  • 0粉丝

博士生

23%

还不是VIP/贵宾

-

威望
0
论坛币
1236 个
通用积分
4.8735
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
2023 点
帖子
75
精华
0
在线时间
407 小时
注册时间
2008-5-16
最后登录
2026-1-26

楼主
shihongjun118 发表于 2022-2-25 18:04:36 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
各位好!
我用stata处理数据时,运用计算生成新变量后,新变量的数值不仅变了,且小数点后面应该有的数也没有了,是怎么回事啊?
数据是这样的:
. dataex qycode goodscode, count(20)
----------------------- copy starting from the next line -----------------------
  1. * Example generated by -dataex-. For more info, type help dataex
  2. clear
  3. input double qycode long goodscode
  4. 3303936223 85351000
  5. 3208930264 40112000
  6. 3303936223 85354000
  7. 3303936223 85389000
  8. 1305910037 70051000
  9. 3109935072 16024910
  10. 4403964580 69079000
  11. 3501969048 64022000
  12. 4428960076 87141900
  13. 3306931134 30051010
  14. 3306931134 30059010
  15. 4401910035 73079900
  16. 3109935072 16023210
  17. 4401910035 73063000
  18. 3214960103 60019200
  19. 4403111049 94060000
  20. 3202330722 85021100
  21. 4428960076 87112010
  22. 4403111049 85179010
  23. 3301949041 61169900
  24. end
复制代码

------------------ copy up to and including the previous line ------------------

我用的命令是:
. gen qygoods=qycode+(goodscode/100000000)
. format qygoods %25.8g

以第一行数据为例,运用以上命令后应该是3303936223.85351000,但结果是3303936256。
本以为是因为goodscode和qycode数据类型不一样,但我改了还是不行。
请问大家,问题出在哪里啊?
跪谢啦!
二维码

扫码加我 拉你入群

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

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

关键词:Stata tata 新变量 小数点 generated

沙发
chendabo 发表于 2023-1-28 22:51:59
你尝试一下在Excel里处理好了再导入Stata软件

藤椅
蓝色 发表于 2023-1-29 16:59:54
Precision of numeric storage types

    floats have about 7 digits of accuracy; the magnitude of the number does not matter.  Thus, 1234567
    can be stored perfectly as a float, as can 1234567e+20.  The number 123456789, however, would be
    rounded to 123456792.  In general, this rounding does not matter.

    If you are storing identification numbers, the rounding could matter.  If the identification
    numbers are integers and take 9 digits or less, store them as longs; otherwise, store them as
    doubles.  doubles have 16 digits of accuracy.


这是帮助里面写的。
double是存储最精确了,但最长只能16位,超过16位就不能精确计算了。
而你的数据整数和小数位数长度超过16了

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

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-29 17:32