全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1750 6
2011-10-28
先是试验用数据test:

data test;
input permno date ret;
cards;
1        20000131        0.846154
1        20000229        0.333333
1        20000331        -0.125
1        20000428        0.357143
1        20000525        -0.15493
1        20000630        0.094017
1        20000735        0.078998
1        20000840        -0.028571
1        20000945        0.117647
1        20001031        -0.052632
1        20001130        -0.333333
1        20001229        0.108333
1        20010131        0.203008
1        20010228        -0.125
1        20010330        -0.028571
1        20010430        0.661944
1        20010531        -0.093205
1        20010629        -0.018692
1        20010731        0.148936
1        20010830        -0.066667
1        20010929        0.015873
1        20011028        0.0625
1        20011127        -0.058824
1        20011226        -0.1875
2        20000131        0.115385
2        20000229        0
2        20000331        -0.137931
2        20000428        -0.04
2        20000525        0.041667
2        20000630        0.28
2        20000735        0.03125
2        20000840        -0.30303
2        20000945        0.076923
2        20001031        0.111111
2        20001130        0.052632
2        20001229        0.175
2        20010131        0.047619
2        20010228        -0.068182
2        20010330        0.242424
2        20010430        0.04878
2        20010531        0.078652
2        20010629        0.020833
2        20010731        0.048421
2        20010830        0.048193
2        20010929        0.044834
2        20011028        -0.029851
2        20011127        -0.092308
2        20011226        0.033898
3        20000131        -0.008197
3        20000229        0.105372
3        20000331        -0.013084
3        20000428        0
3        20000525        -0.05303
3        20000630        0.128
3        20000735        -0.060284
3        20000840        0.037736
3        20000945        0.050909
3        20001031        -0.114187
3        20001130        0.015625
3        20001229        -0.030769
3        20010131        -0.126984
3        20010228        0.018182
3        20010330        0.049107
3        20010430        -0.021277
3        20010531        -0.013043
3        20010629        0.145374
3        20010731        -0.015385
3        20010830        0.007813
3        20010929        0.007752
3        20011028        -0.023077
3        20011127        0.055118
3        20011226        -0.003731
4        20000131        0.014981
4        20000229        -0.01845
4        20000331        -0.109023
4        20000428        -0.004219
4        20000525        -0.025424
4        20000630        0.034783
4        20000735        0.004202
4        20000840        -0.037657
4        20000945        0.2
4        20001031        0.007246
4        20001130        0.046763
4        20001229        -0.092784
4        20010131        0.094697
4        20010228        0.224913
4        20010330        0.039548
4        20010430        0.032609
4        20010531        0.142857
4        20010629        -0.065789
4        20010731        -0.096774
4        20010830        -0.232143
4        20010929        0.069767
4        20011028        0.217391
4        20011127        -0.107143
4        20011226        -0.12
5        20000131        0.090909
5        20000229        -0.083333
5        20000331        -0.090909
5        20000428        0.25
5        20000525        0.16
5        20000630        0.416667
5        20000735        -0.039216
5        20000840        0.102041
5        20000945        0.055556
5        20001031        0.035088
5        20001130        0.169492
5        20001229        0
5        20010131        -0.188406
5        20010228        0.321429
5        20010330        -0.027027
5        20010430        -0.013889
5        20010531        -0.239437
5        20010629        -0.148148
5        20010731        0
5        20010830        0.108696
5        20010929        -0.098039
5        20011028        0
5        20011127        0.304348
5        20011226        -0.116667
6        20000131        -0.132075
6        20000229        -0.111111
6        20000331        0
6        20000428        0.210526
6        20000525        0.130435
6        20000630        0.269231
6        20000735        -0.121212
6        20000840        0
6        20000945        0.206897
6        20001031        -0.057143
6        20001130        0.30303
6        20001229        0.27907
6        20010131        0.054545
6        20010228        0.310345
6        20010330        0.078947
6        20010430        0.207317
6        20010531        0.068182
6        20010629        -0.049645
6        20010731        0.089552
6        20010830        0.068493
6        20010929        0.012821
6        20011028        -0.025316
6        20011127        0.090909
6        20011226        -0.166667
7        20000131        -0.1
7        20000229        -0.047619
7        20000331        0.166667
7        20000428        -0.042857
7        20000525        0.029851
7        20000630        -0.246377
7        20000735        -0.096154
7        20000840        0.021277
7        20000945        0.270833
7        20001031        -0.081967
7        20001130        0.089286
7        20001229        0.008197
7        20010131        0.105691
7        20010228        -0.102941
7        20010330        0.147541
7        20010430        -0.042857
7        20010531        -0.044776
7        20010629        -0.078125
7        20010731        -0.050847
7        20010830        -0.160714
7        20010929        0
7        20011028        0.005319
7        20011127        -0.100529
7        20011226        -0.035294
8        20000131        -0.073171
8        20000229        -0.105263
8        20000331        0.470588
8        20000428        -0.02
8        20000525        0.020408
8        20000630        -0.04
8        20000735        0
8        20000840        0.125
8        20000945        0.240741
8        20001031        0.089552
8        20001130        -0.089041
8        20001229        -0.052632
8        20010131        0.079365
8        20010228        -0.022059
8        20010330        -0.165414
8        20010430        -0.009009
8        20010531        -0.054545
8        20010629        -0.076923
8        20010731        0.125
8        20010830        0.12963
8        20010929        -0.122951
8        20011028        -0.009346
8        20011127        0.103774
8        20011226        0.162393
9        20000131        0.058824
9        20000229        -0.069444
9        20000331        0.895522
9        20000428        -0.094488
9        20000525        0.026087
9        20000630        -0.110169
9        20000735        0.438095
9        20000840        0.478477
9        20000945        -0.06383
9        20001031        0.107656
9        20001130        0.213823
9        20001229        -0.153025
9        20010131        -0.105042
9        20010228        -0.441315
9        20010330        0.042017
9        20010430        0.41129
9        20010531        -0.091429
9        20010629        0.106918
9        20010731        -0.022727
9        20010830        -0.075581
9        20010929        0.015723
9        20011028        -0.20743
9        20011127        0.210938
9        20011226        0.283871
10        20000131        0.20603
10        20000229        0.129167
10        20000331        0.180812
10        20000428        -0.182812
10        20000525        -0.147228
10        20000630        0.197309
10        20000735        -0.08427
10        20000840        -0.014315
10        20000945        0.062241
10        20001031        -0.070313
10        20001130        0.029412
10        20001229        -0.134694
10        20010131        0.485849
10        20010228        0.11746
10        20010330        0.056818
10        20010430        0.214382
10        20010531        0.179856
10        20010629        0.150094
10        20010731        0.089723
10        20010830        0.353293
10        20010929        -0.001659
10        20011028        0.371745
10        20011127        -0.088853
10        20011226        0.009709
;
run;
data msex2;
        set test;
        year=floor(date/10000);
        month=floor((date-year*10000)/100);
        date=mdy(month,28,year);
        format date mmddyy10.;
        yearmo=year*100+month;
run;
关键的是下面这段:
proc sql;            create table umd1   
       as select distinct a.permno, a.date, exp(sum(log(1+b.ret))) - 1 as cum_return   
       from msex2 (keep=permno date) as a, msex2 as b        
       where a.permno=b.permno and 0<=intck('month', b.date, a.date)<3  
       group by a.permno, a.date  
       having count(b.ret)=3;
quit;


我至今不太明白这里的逻辑思路是什么?具体有如下问题:
1、这里的distinct是只选择了非重复的permno,但是由于这里是panel data,so "distinct" can do nothing here;
2.  when is the cum_return  calculated? after " where a.permno=b.permno and 0<=intck('month', b.date, a.date)<3 " by a.permno, a.date  ?

Thanks for your help in advance~!


二维码

扫码加我 拉你入群

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

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

全部回复
2011-10-29 21:24:56
高人都放假了吗?
二维码

扫码加我 拉你入群

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

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

2011-10-30 01:52:37
这帖子看来是没有人愿意回答了。今天自己弄明白了,自言自语一下吧
1、由于是panel data,所以distinct在这里没有作用;加distinct的作用在于避免重复数据的出现,所以最好还是带着;
2、计算是在where a.permno=b.permno and 0<=intck('month', b.date, a.date)<3 语句之后
二维码

扫码加我 拉你入群

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

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

2011-10-30 02:09:41
你已经group by  就已经确定1,2 字段唯一了  不需要distinct的。。
二维码

扫码加我 拉你入群

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

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

2011-10-30 03:51:02
numman 发表于 2011-10-30 02:09
你已经group by  就已经确定1,2 字段唯一了  不需要distinct的。。
的确,这里的distinct是多余了。
但我发现distinct的另外作用是,在没有group by 的条件下可以对数据排序
二维码

扫码加我 拉你入群

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

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

2011-10-30 12:59:55
denver 发表于 2011-10-30 03:51
的确,这里的distinct是多余了。
但我发现distinct的另外作用是,在没有group by 的条件下可以对数据排序 ...
distinct 效率很低的  平时能不用就不用了。。
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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