楼主: jingmaths
59 1

[SAS EM] CAPM模型检验BJS法SAS代码 [推广有奖]

  • 1关注
  • 0粉丝

等待验证会员

学前班

60%

还不是VIP/贵宾

-

威望
0
论坛币
9 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
43 点
帖子
2
精华
0
在线时间
2 小时
注册时间
2019-9-11
最后登录
2019-9-20

jingmaths 发表于 2019-9-12 10:57:06 |显示全部楼层
求大神指点,刚学金融计量学和SAS,下面代码是按照书上内容打出来的,但下面出错
求大神帮忙修改运行不出部分


libname CAPM 'D:\SAS\3.2in';
data capm.riraw;                    
infile 'D:\SAS\fe\Chap3-2-1 BJS.csv' delimiter = ' , ' MISSOVER DSD lrecl=5000;
input date r1-r25 rf rm;   
run;/*导入原始数据——收益率*/
data capm.rida;
infile 'D:\SAS\3.2in\Chap3-2-1 date.csv' delimiter = ' , ' MISSOVER DSD lrecl=5000;
input date date1;   
run;/*从capm.riraw中读取date ri rf rm code,其中code取1-25,用来提取r1-r25分别放入不同的数据集中*/
%macro mac;
%do i=1 %to 25;
data capm.ri&i.;
set capm.riraw;
code=&i.;
ri=r&i.;
keep date ri rf rm code;
run;
%End;
%MEND mac;
%mac;
data capm.ri;
set capm.ri1 capm.ri2 capm.ri3 capm.ri4 capm.ri5 capm.ri6 capm.ri7 capm.ri8 capm.ri9 capm.ri10 capm.ri11 capm.ri12 capm.ri13 capm.ri14 capm.ri15 capm.ri16 capm.ri17 capm.ri18 capm.ri19 capm.ri20 capm.ri21 capm.ri22 capm.ri23 capm.ri24 capm.ri25;
run;
proc sort data=capm.ri; by date; run;
proc sort data=capm.rida; by date;run;

data capm.riraw1;
merge capm.ri capm.rida; by date;
rif=ri-rf;rmf=rm-rf;
run;
proc sort data=capm.riraw1; by code;run;
%macro mac;
%do i=1 %to 30;
data capm.t&i.;
set capm.riraw1;
if date1>=&i. and date1<=35+&i.;
rif=ri-rf;rmf=rm-rf;
run;
%End;
%MEND mac;
%mac;
/*以上可运行出来,下面运行出来出错*/

%macro mac;


%do i=1 %to 30;


datacapm.t&i.;


setcapm.riraw1;


ifdate1>=&i. and date1<=35+&i.;


rif=ri-rf;rmf=rm-rf;


run;


%End;


%MEND mac;


%mac;



%macro mac;


%do i=1 %to 30;


datacapm.t&i.;


setcapm.riraw1;


ifdate1>=&i. and date1<=35+&i.;


rif=ri-rf; rmf=rm-rf;


run;



proc reg data=capm.t&i.;


outest=capm.beta_&i.;


by code;


model rif=rmf;


run;




proc rank data=capm.beta_&i. out=capm.beta&i.groups=5;


ranks p =input(rmf,grpfmt.);


var rmf;


run;


%End;


%MEND mac;


%mac;



%macro mac;


%do i=1 %to 30;


data capm.beta&i.;


set capm.beta&i.;


date1=&i.+36;


keep code date1p;


run;


%End;


%MEND mac;


%mac;




data capm.cop;


set capm.beta1;


run;


%macro mac;


%do i=1 %to 30;


data capm.cop;


merge capm.copcapm.beta&i.;


by code date1;


run;


%End;


%MEND mac;


%mac;




data capm.riraw2;


set capm.riraw1;


if date1>=37 and date1<=66;


run;




proc sort data=capm.riraw2;


by code;run;


proc sort data=capm.riraw2;


by date1;run;


proc sort data=capm.cop;


by code;run;


proc sort data=capm.cop;


by date1;run;




data capm.cop2;


merge capm.cop capm.riraw2;


by date1 code;


keep code date1 ri rm rf p;


run;



proc sort data=capm.cop2;


by p date1;run;


proc univariate data=capm.cop2


var ri rm rf;


by p datel;



output out=capm.rip


mean=meanri mean=meanrmmean=meanrf;


run;



data capm.rip1;


set capm.rip;


meanrif=meanri-meanrf;


meanrmf=meanrm-meanrf;


run;


proc sort data=capm.rip1 ;


by p;run;


proc reg data=capm.rip1


outest=capm.beta;


model meanrif=meanrmf;


by p;


run;



proc univariate data=capm.rip1;


var meanri;


by p;


output out=capm.rip2


mean=meanrip;


run;


data capm.beta0;


merge capm.beta capm.rip2;


by p;


run;


proc reg data=capm.beta0;


model meanrip=meanrmf;


run;




3.2in.zip

10.07 KB

数据

stata SPSS
whymath 发表于 2019-9-13 20:51:08 |显示全部楼层
1. 许多地方少了空格,第一次出现在:
datacapm.t&i.;
应该是
data capm.t&i.;

2. 较多的程序语句顺序有误,第一次出现在:
if date1>=&i. and date1<=35+&i.;
rif=ri-rf;rmf=rm-rf;
应该是
rif=ri-rf;rmf=rm-rf;
if date1>=&i. and date1<=35+&i.;
回复

使用道具 举报

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

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

GMT+8, 2019-9-20 22:48