我的时间序列里面的时间表达是:121998 (也就是1998年12月)
我想把它拆成两列,一列只有月份,一列只有年份。
请问需要用哪个命令?怎么操作?
谢谢。。。。
请注明:姓名-公司-职位
以便审核进群资格,未注明则拒绝
tostring date, gen(date1)gen year1 = substr(date1,3,4)gen year = real(year1)
gen month1 = substr(date1,1,2)
gen month = real(month)
首先确定时间变量是字符型,如果不是用tostring命令转换。
gen month=substr(time,1,2)
gen year=substr(time,3,4)
谢谢楼上两位的答案。我分离出了年。但月份还有问题。
因为我的数据的日期表达是这样的:
11988
21988
......
121988
我用了gen month=substr(date, 1,2)
那么出现的是:
11
21
.....
12
但其实应该是:
1
2
3
。。。
请问如何解决呢?
谢谢。。。
前提:设原始数据中,时间变量time属字符型
gen month=int(real(time)/10000)
gen year=real(time)-month*10000
**前提:设原始数据中,时间变量time属数值型
gen month=int(time/10000)
gen year=time-month*10000
******以上两种结果中month与year都是数值型变量
gen time=string(date)gen year1=substr(time,-4,4)gen rtime=reverse(time)gen month1=substr(rtime,5,.)gen year=real(year1)gen month=real(reverse(month1))