全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
433 0
2025-02-20
opencellid数据中有两个变量:
<created>integerThe first time when the cell tower was seen and added to the OpenCellID database.
A date in timestamp format:
number of seconds since the UTC Unix Epoch of 1970-01-01T00:00:00Z
For example 1409522613 is the timestamp for 2014-08-31T22:03:33Z.
<updated>integerThe last time when the cell tower was seen and update.
A date in timestamp format:
number of seconds since the UTC Unix Epoch of 1970-01-01T00:00:00Z
For example 1409522613 is the timestamp for 2014-08-31T22:03:33Z.

https://wiki.opencellid.org/wiki/Database_format
我想把这两个变量设置为 stata中的时间变量。遇到了几个问题,解决后把过程梳理如下:

1.可以看到,这两个变量是从1970起计算的秒数,由此来衡量时间。事实上stata中也是这样计算时间,不同的是起始的时间为1960年。因此两者之间存在一定的差距。把数据导入到stata后,在created、updated两个变量基础上,应该加上从1960年到1970年的秒数。AI算了一下,大概是315619200秒。


2.加上以后,生成变量created_datetime ,把这个变量转为时间格式:

复制代码



发现都是1960年,肯定不对。再研究一下,发现%tc这个格式下的单位应该是毫秒,也就是1/1000秒。help文件里说“datetime/c 和 datetime/C 变量的默认格式会省略秒的小数部分;15:15:30.000 会显示为 15:15:30。如果你希望看到秒的小数部分,请指定相应格式。”也就是说虽然默认显示到秒,但是实际上是毫秒,也就是说应该在原来基础上乘1000。于是用:


[color=var(--md-box-samantha-normal-text-color)]
复制代码



官方给的例子,1409522613 is the timestamp for 2014-08-31T22:03:33Z.
按照上述尝试后,得到31aug2014 22:04:36,略微有些出入,应该是AI计算的秒数有一点点问题。但问题不大。反正大概只需要看年份就行。

问题解决!
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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