在stata中有变量名date,如2007-12-31,2008-12-31,查看数据类型为%10s,怎样转化为日期型类型。
我试了 gen x=date(date,"YMD"),format x %td。
但x均为缺失值?为什么?怎么处理?非常感谢!
另外我还试了一下这种方法发现还是不行:gen datenew=date(substr(date, 1,4))+substr(date,6,2)+substr(date, 9,2), "MDY")
format datenew %td.
**导入的原数据列是yyyy-mm-dd非日期型数据格式转化为yyyymm日期型格式数据***
**转化为月度日期型
gen time1 = date(date1,"YMD")
format time1 %td
gen year1 = year(time1)
gen month1 = month(time1)
gen time = ym(year1,month1)
format time %tm