楼主: xwan5667
4347 13

[数据管理求助] 菜鸟求助stata数据清理时间变量问题 [推广有奖]

  • 1关注
  • 0粉丝

大专生

56%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
31.0968
学术水平
1 点
热心指数
3 点
信用等级
1 点
经验
857 点
帖子
49
精华
0
在线时间
40 小时
注册时间
2013-2-8
最后登录
2019-7-3

楼主
xwan5667 发表于 2014-4-28 17:12:46 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
如题所述,请路过的好心人指点一下本菜鸟~~
我的数据库中,时间类型是yyyy-mm-dd,现在想要转换成yyyymmdd,有几万条数据,如何进行转换呢?
如下图,数据中时间格式有两种,我束手无策啦。

谢谢~
360软件小助手截图20140429165340.png
二维码

扫码加我 拉你入群

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

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

关键词:求助stata STATA数据 Stata 数据清理 时间变量 数据库 清理 时间变量转换

回帖推荐

hplcdadong 发表于8楼  查看完整内容

See, your second post is quite different from the first one (25jun2013 is different from 2013/06/25). Here is the solution: gen date_n=date(substr(trim(admission_date),1,10), "YMD") replace date_n=date(trim(admission_date), "DMY") if missing(date_n) format date_n %tdCCYY/NN/DD

hplcdadong 发表于3楼  查看完整内容

Assume your original "admission date" is string variable when you import it into Stata, based on your presented data here, try the following (replace "admission_date with your own real date variable): gen date_n=date(substr(admission_date,1,10), "YMD") format date_n %tdCCYY/NN/DD

沙发
xwan5667 发表于 2014-4-29 16:56:43
请知道的人给指导一下吧。

藤椅
hplcdadong 发表于 2014-4-29 21:40:33
Assume your original "admission date" is string variable when you import it into Stata, based on your presented data here, try the following (replace "admission_date with your own real date variable):

gen date_n=date(substr(admission_date,1,10), "YMD")     
format date_n %tdCCYY/NN/DD
已有 1 人评分经验 论坛币 学术水平 热心指数 收起 理由
crystal8832 + 12 + 24 + 3 + 3 热心帮助其他会员

总评分: 经验 + 12  论坛币 + 24  学术水平 + 3  热心指数 + 3   查看全部评分

板凳
xwan5667 发表于 2014-5-3 13:36:56
hplcdadong 发表于 2014-4-29 21:40
Assume your original "admission date" is string variable when you import it into Stata, based on you ...
thanks so much~it worked!

But there is still a problem, the one in blue was treated as missing data. Would you please kindly help me with this?

报纸
╰不滅信念 学生认证  发表于 2014-5-4 00:25:07
Make sure that there are no blanks in the front of this record
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
经济大菜鸟 + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

where there is a will there is a way

地板
hplcdadong 发表于 2014-5-4 01:47:24
Try this:

gen date_n=date(substr(trim(admission_date),1,10), "YMD")     
format date_n %tdCCYY/NN/DD

7
xwan5667 发表于 2014-5-7 11:46:45
hplcdadong 发表于 2014-5-4 01:47
Try this:

gen date_n=date(substr(trim(admission_date),1,10), "YMD")
Both way treat the other type of date as misssing data :(
date.png        missing data was shown after converting I tried both ways
Would you please kindly give me some other suggestions?

Thanks!

8
hplcdadong 发表于 2014-5-7 21:37:10
See, your second post is quite different from the first one (25jun2013 is different from 2013/06/25). Here is the solution:

gen date_n=date(substr(trim(admission_date),1,10), "YMD")
replace date_n=date(trim(admission_date), "DMY") if missing(date_n)   
format date_n %tdCCYY/NN/DD

9
xwan5667 发表于 2014-5-8 22:27:20
hplcdadong 发表于 2014-5-7 21:37
See, your second post is quite different from the first one (25jun2013 is different from 2013/06/25) ...
Thanks for all the solutions and kind help! It finally worked :) except for 3 of them.

10
xwan5667 发表于 2014-7-25 09:30:31
hplcdadong 发表于 2014-5-7 21:37
See, your second post is quite different from the first one (25jun2013 is different from 2013/06/25) ...
Hi there, thx for your previous help!

I am still struggling with my data :(

I tried to import the other data from excel to stata, but
1. stata told me "....is too big"
2. when I tried to import part of the data, all the variables in Chinese gone~

just wondering, what happened and what should I do?

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

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