全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
1605 2
2009-09-02
本人在初次使用STATA处理数据,需到如下问题,希望高手帮忙。使用数据如下:
jjdmdatecgslgpmc
1846882003-3-312875996赛格三
1846882003-3-3112614982深圳机
1846882003-3-3185960凯迪电
1846882003-3-31289560浦发银
1846882003-3-31274859华能国
1846882003-3-313758569民生银
1846882003-3-31464669宝钢股
1846882003-3-3175866福田汽
1846882003-3-317586贵州茅
1846882003-3-318567天士力
1846882003-6-303126243五粮液
1846882003-6-303000000赛格三
1846882003-6-3012614982深圳机
1846882003-6-30700000穗恒运
1846882003-6-301700000粤TCLA
1846882003-6-302000000万向钱
1846882003-6-301300000韶能股
1846882003-6-30526363铜都铜
1846882003-6-30448284福地科
1846882003-6-301590851金牛能

其中jjdm,date,cgsl,gpmc分别表示基金代码、日期、持股数量及股票代码,现在要做的处理是:如果2003-3-31和2003-6-30中gpmc中有相同股标,则用2003-6-30的cgsl减去2003-3-31年的cgsl,用X变量表示,否则取值为0。gpmc为字符型,请问要做这些要使用哪些命令?请高手指点,不胜感激!!
二维码

扫码加我 拉你入群

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

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

全部回复
2009-9-2 23:19:26
你的date是字符型吗?其中只有两种数值吗?
二维码

扫码加我 拉你入群

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

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

2009-9-5 23:29:58
i assume your dates are either 2003-6-30 or 2003-3-31, and you consider the difference for the same jjdm. also, i assume that given the same jjdm, there will be only ONE date for each gpmc.

* step 1:

bys jjdm  gpmc (date): gen x=cgsl-cgsl[_n-1]

jjdm        date        cgsl        gpmc        x
184688        3/31/2003        75866        a       
184688        6/30/2003        1300000        a        1224134
184688        3/31/2003        7586        b       
184688        6/30/2003        12614982        b        1.26E+07
184688        3/31/2003        85960        c       
184688        6/30/2003        448284        c        362324
184688        3/31/2003        289560        d       
184688        6/30/2003        2000000        d        1710440
184688        3/31/2003        274859        e       
184688        6/30/2003        3126243        e        2851384
184688        3/31/2003        2875996        f       
184688        3/31/2003        8567        f        -2867429
184688        3/31/2003        12614982        g       
184688        3/31/2003        464669        g        -1.22E+07
184688        3/31/2003        3758569        h       
184688        6/30/2003        3000000        h        -758569
184688        6/30/2003        700000        i       
184688        6/30/2003        1700000        i        1000000
184688        6/30/2003        526363        j       
184688        6/30/2003        1590851        j        1064488

* if you want to set the same x value for the same jjdm  and gpmc, then:

bys jjdm  gpmc (x): replace x=x[1]

* step 2:

Now, you can set the rest of x to 0:
replace x=0 if x==.

hope this helps
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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