全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
4912 5
2017-03-24
stata 怎么处理月份为英文缩写的时期型变量
例如我的日期为“31oct16”。日月年
直接用 date(var, "DMY") 不行
二维码

扫码加我 拉你入群

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

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

全部回复
2017-3-24 22:41:59
本人已经解决,使用了笨办法,供大家参考批评!
deadline 即为所处理的时间变量

******时期变量处理

replace deadline = lower(deadline)

split deadline, parse("-") gen(ndate) notrim

rename ndate1 date
rename ndate2 month
rename ndate3 year
*****月份为英文缩写处理方法*******************

replace month = subinstr(month, "jan", "01",.)
replace month = subinstr(month, "feb", "02",.)
replace month = subinstr(month, "mar", "03",.)
replace month = subinstr(month, "apr", "04",.)
replace month = subinstr(month, "may", "05",.)
replace month = subinstr(month, "jun", "06",.)
replace month = subinstr(month, "jul", "07",.)
replace month = subinstr(month, "aug", "08",.)
replace month = subinstr(month, "sep", "09",.)
replace month = subinstr(month, "oct", "10",.)
replace month = subinstr(month, "nov", "11",.)
replace month = subinstr(month, "dec", "12",.)

**********************************************
*****将year格式补充完整

replace year = "20" + year


destring date month year, replace

gen deadlineymd = mdy(month, date, year)
gen deadlineym = ym(year, month)
format deadlineym %tm
附件列表
deadline.PNG

原图尺寸 8.14 KB

deadline.PNG

二维码

扫码加我 拉你入群

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

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

2017-3-25 05:01:28
用gen date=date(datestr,"DM20Y")即可
help datetime_translation
二维码

扫码加我 拉你入群

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

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

2017-3-25 08:38:51
夏目贵志 发表于 2017-3-25 05:01
用gen date=date(datestr,"DM20Y")即可
help datetime_translation
谢谢 我试一下
二维码

扫码加我 拉你入群

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

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

2023-11-30 21:18:17
救我大命了,谢谢楼主
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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