楼主: bonniehuangyan
5260 6

[求助]STATA中如何分隔年月 [推广有奖]

  • 0关注
  • 0粉丝

已卖:26份资源

博士生

43%

还不是VIP/贵宾

-

威望
0
论坛币
358 个
通用积分
3.8396
学术水平
0 点
热心指数
1 点
信用等级
1 点
经验
1557 点
帖子
161
精华
0
在线时间
362 小时
注册时间
2007-2-14
最后登录
2023-10-10

楼主
bonniehuangyan 发表于 2008-10-14 21:39:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

我的时间序列里面的时间表达是:121998 (也就是1998年12月)

我想把它拆成两列,一列只有月份,一列只有年份。

请问需要用哪个命令?怎么操作?

谢谢。。。。

二维码

扫码加我 拉你入群

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

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

关键词:Stata tata 时间序列 怎么操作 时间表 Stata 分隔

回帖推荐

songking 发表于7楼  查看完整内容

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)) ******以上两种结果中month与year都是数值型变量

sungmoo 发表于5楼  查看完整内容

前提:设原始数据中,时间变量time属字符型gen month=int(real(time)/10000)gen year=real(time)-month*10000

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

首先确定时间变量是字符型,如果不是用tostring命令转换。gen month=substr(time,1,2)gen year=substr(time,3,4)

arlionn 发表于2楼  查看完整内容

tostring date, gen(date1)gen year1 = substr(date1,3,4)gen year  = real(year1)gen month1 = substr(date1,1,2)gen month  = real(month)

本帖被以下文库推荐

沙发
arlionn 在职认证  发表于 2008-10-15 11:12:00

tostring date, gen(date1)
gen year1 = substr(date1,3,4)
gen year  = real(year1)

gen month1 = substr(date1,1,2)

gen month  = real(month)

藤椅
liuxb 发表于 2008-10-15 11:18:00

首先确定时间变量是字符型,如果不是用tostring命令转换。

gen month=substr(time,1,2)

gen year=substr(time,3,4)

板凳
bonniehuangyan 发表于 2008-10-15 18:37:00

谢谢楼上两位的答案。我分离出了年。但月份还有问题。

因为我的数据的日期表达是这样的:

11988

21988

......

121988

我用了gen month=substr(date, 1,2)

那么出现的是:

11

21

.....

12

但其实应该是:

1

2

3

。。。

12

请问如何解决呢?

谢谢。。。

报纸
sungmoo 发表于 2008-10-16 04:10:00

前提:设原始数据中,时间变量time属字符型

gen month=int(real(time)/10000)

gen year=real(time)-month*10000

地板
sungmoo 发表于 2008-10-16 04:15:00

**前提:设原始数据中,时间变量time属数值型

gen month=int(time/10000)

gen year=time-month*10000

******以上两种结果中month与year都是数值型变量

7
songking 发表于 2008-10-16 12:38:00

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))

******以上两种结果中month与year都是数值型变量

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

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