请选择 进入手机版 | 继续访问电脑版
楼主: yin8
1307 4

求计算状态转移 [推广有奖]

  • 0关注
  • 0粉丝

本科生

4%

还不是VIP/贵宾

-

威望
0
论坛币
49 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
1128 点
帖子
12
精华
0
在线时间
120 小时
注册时间
2010-6-7
最后登录
2014-8-28

yin8 发表于 2014-8-22 10:57:58 |显示全部楼层 |坛友微信交流群
100论坛币
如图所示,我已经按照每年每月,按照monret指标分好五组。现在想计算出的是一个组间股票转移的情况。具体的步骤为,在t月份,按照当期的monret分成五组0,1,2,3,4;在t+1月,计算还有多少比率的股票仍然在t时期所在组;第t+2月,计算还有多少比率的股票仍然在t时期所在组;一直计算到t+4期。然后按照每个月分别在未来1,2,3,4月的情况,求出这种转移率的平均

最后希望能呈现大概如下的样子
thanks
zhuanyi1.jpg
zhuanyi.jpg

zhuanyi.xls

10.44 MB

关键词:thanks Thank 如图所示 Hank Than 如图所示

回帖推荐

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

freerunning_sky 在职认证  发表于 2014-8-22 10:57:59 |显示全部楼层 |坛友微信交流群
  1. proc import out=input
  2.         datafile="C:\tmp\zhuanyi.xls"
  3.         dbms=excel replace;
  4. run;

  5. proc sql;
  6.         create table out as
  7.         select distinct a.year,a.month,
  8.         sum((a.year=b.year)*(a.month=b.month)) as tot,
  9.         sum(((b.year-a.year)*12+b.month-a.month=1)*(a.rflag=b.rflag)) as cnt_1,
  10.         sum(((b.year-a.year)*12+b.month-a.month=2)*(a.rflag=b.rflag)) as cnt_2,
  11.         sum(((b.year-a.year)*12+b.month-a.month=3)*(a.rflag=b.rflag)) as cnt_3,
  12.         sum(((b.year-a.year)*12+b.month-a.month=4)*(a.rflag=b.rflag)) as cnt_4
  13.         from input a
  14.         left join input b on a.stkcd=b.stkcd
  15.         group by a.year,a.month
  16.         order by a.year,a.month;
  17. quit;

  18. proc sql;
  19.         select max(year),max(month) into :max_year,:max_mth from input;
  20. quit;

  21. data out1;
  22.         retain time tot rate_1-rate_4;
  23.         keep time tot rate_1-rate_4;
  24.         set out;
  25.         time=compress(year||put(month,Z2.));
  26.         array cnt(*) cnt_1-cnt_4;
  27.         array rate(*) rate_1-rate_4;
  28.         do i=1 to dim(cnt);
  29.                 if (&max_year-year)*12+&max_mth-month<=i-1 then rate(i)=.;else
  30.                 rate(i)=cnt(i)/tot;
  31.         end;
  32.         format rate_1-rate_4 percent12.2;
  33. run;
复制代码

使用道具

yin8 发表于 2014-8-22 20:58:49 |显示全部楼层 |坛友微信交流群
rflag就是根据每年每月对monret分好组的

使用道具

yin8 发表于 2014-8-23 08:35:08 |显示全部楼层 |坛友微信交流群
freerunning_sky 发表于 2014-8-22 14:02
不好意思,可能我没有表达清楚,我再想想怎么表达

使用道具

yongyitian 发表于 2014-8-23 10:56:04 |显示全部楼层 |坛友微信交流群
  1. /* 和楼上的方法一样,加了两个变量,看起来好懂些。 
  2. sum(condition)函数()内部的条件满足时值为 1,不满足时为0. */


  3. PROC IMPORT OUT= WORK.zhuanyi_all
  4.    DATAFILE= "C:\temp\zhuanyi.xls"
  5.                DBMS = EXCEL REPLACE;
  6.               SHEET = "Sheet1$";
  7. RUN;

  8. data test_all;
  9.    set zhuanyi_all;
  10.    ym = mdy(month, 1, year);   
  11.    id = cats(stkcd, '_', put(rflag, 1.));
  12.    format ym yymmdd10.;
  13. run;

  14. proc sql;
  15.     create table t1  as
  16.     select  a.ym, sum( intck('month', a.ym, b.ym)=0 ) as t0,
  17.                   sum( intck('month', a.ym, b.ym)=1 ) as t1,
  18.                   sum( intck('month', a.ym, b.ym)=2 ) as t2,
  19.                   sum( intck('month', a.ym, b.ym)=3 ) as t3,
  20.                   sum( intck('month', a.ym, b.ym)=4 ) as t4
  21.     from test_all a, test_all b
  22.     where a.id=b.id
  23.     group by a.ym;
  24. quit;
复制代码
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
yin8 + 5 + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 5  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-19 09:12