格兰杰因果关系检验的SAS实现 eviews格兰杰因果检验

%macrocausal(data= , y = ,drivers = , max_lags = );
***********************************************************;
*THIS SAS MACRO IS AN IMPLEMENTATION OFBI-VARIATE*;
*GRANGER CAUSALITY TEST PROPOSED BY GRANGER(1969)*;
*=======================================================*;
*PAMAMETERS:*;
*DATA: INPUT SAS DATATABLE*;
*Y:A CONTINUOUS TIME SERIES RESPONSEVARIABLE*;
*DRIVERS:A LIST OF TIME SERIESPREDICTORS*;
*MAX_LAGS : MAX # OFLAGS TO SEARCH FORCAUSAL*;
*RELATIONSHIPS*;
*=======================================================*;
*CONTACT:*;
*WENSUI.LIU@53.COM,LOSS FORECASTING & RISKMODELING*;
***********************************************************;

optionsnocenter nonumbernodate mprint mlogic symbolgen orientation = landscape
ls= 150formchar ="|----|+|---+=|-/<>*";

%macrogranger(data=, dep = , indep = , nlag = );

%letlag_dep = ;
%letlag_indep = ;

data_tmp1;
set&data(keep=&dep&indep);

%doi = 1%to&nlag;
lag&i._&dep=lag&i.(&dep);
lag&i._&indep=lag&i.(&indep);

%letlag_dep =&lag_deplag&i._&dep;
%letlag_indep =&lag_indeplag&i._&indep;
%end;
run;

proccorrdata= _tmp1noprint outp = _corr1(rename= (&dep=value) where= (_type_ ='CORR')) nosimple;
var&dep;
with lag&nlag._&indep;
run;

proccorrdata= _tmp1noprint outp = _corr2(rename= (&dep=value) where= (_type_ ='CORR')) nosimple;
var&dep;
格兰杰因果关系检验的SAS实现 eviews格兰杰因果检验
with lag&nlag._&indep;
partial lag&nlag._&dep;
run;

procregdata= _tmp1noprint;
model &dep=&lag_dep;
outputout = _rest1 r =rest_e;
run;

procregdata= _tmp1noprint;
model &dep=&lag_dep&lag_indep;
outputout = _full1 r =full_e;
run;

procsqlnoprint;
selectsum(full_e * full_e) into:full_sse1from_full1;

selectsum(rest_e * rest_e) into:rest_sse1from_rest1;

selectcount(*)into:nfrom_full1;

selectvalue into:cor1 from_corr1;

selectvalue into:cor2 from_corr2;
quit;

data_result;
formatdep $20. ind $20.;
dep= "&dep";
ind= "%upcase(&indep)";
nlag = &nlag;

corr1 = &cor1;
corr2 = &cor2;

f_test1=((&rest_sse1-&full_sse1) /&nlag) /(&full_sse1/(&n-2*&nlag-1));
p_ftest1 = 1- probf(f_test1, &nlag, &n-2*&nlag-1);

chisq_test1 = (&n*(&rest_sse1-&full_sse1)) /&full_sse1;
p_chisq1=1- probchi(chisq_test1, &nlag);

formatflag1 $3.;
ifmax(p_ftest1, p_chisq1) <0.01thenflag1 = "***";
elseifmax(p_ftest1, p_chisq1) <0.05thenflag1 = "**";
elseifmax(p_ftest1, p_chisq1) <0.1thenflag1 = "*";
elseflag1 = "";
run;

%mendgranger;

data_in1;
set&data(keep=&y&drivers);
run;

%letvar_loop =1;

%do%while(%scan(&drivers, &var_loop) ne %str());

%letdriver = %scan(&drivers, &var_loop);

%dolag_loop =1%to&max_lags;

%granger(data=_in1, dep = &y,indep = &driver, nlag =&lag_loop);

%if&var_loop=1&&lag_loop=1%then%do;
data_final;
set_result;
run;
%end;
%else%do;
data_final;
set_final_result;
run;
%end;
%end;

%letvar_loop =%eval(&var_loop+1);
%end;

title;
procreportdata=_last_ box spacing = 1split ="/"nowd;
column("GRANGERCAUSALITY TEST FOR %UPCASE(&y) UPTO&MAX_LAGS LAGS"
ind nlag corr1 corr2 f_test1 chisq_test1 flag1);

defineind/ "DRIVERS"width= 20centergrouporderorder= data;
definenlag/"LAG"width= 3format=3.center orderorder= data;
definecorr1/ "PEARSON/CORRELATION"width= 12format= 8.4center;
definecorr2/ "PARTIAL/CORRELATION"width= 12format= 8.4center;
definef_test1/ "CAUSAL/F-STAT"width= 12format= 10.4center;
define chisq_test1 /"CAUSAL/CHISQ-STAT"width= 12format= 10.4center;
defineflag1/ "CAUSAL/FLAG"width= 8right;
run;

%mendcausal;

�usal(data=sashelp.citimon, y = RTRR, drivers = CCIUTC LHUR FSPCON, max_lags =6);


  

爱华网本文地址 » http://www.aihuau.com/a/25101014/215104.html

更多阅读

关于师生关系本质的认识 认识的本质是

关于师生关系本质的认识□李瑾瑜近年来,由于教育的民主化、人道化、效率化进程的加快,以及教育教学改革对内部深层次问题的触及,师生关系成了人们关注的热点问题之一。同时,师生关系也是一个在理论上需要深入研究,在实践中急待精

关于党组织关系转移的问题 党组织关系可以转到哪

问:我是08年6月大学毕业的,之后回家乡的一家单位工作,先是半年的试用期,到09年1月才跟我正式签约的。大学在毕业前开给我的党组织关系转移的介绍信,只有3个月的期限,到08年9月就过期了。现在单位说他们自己没有党组织,我的党组织关系转移转

刘江永:钓鱼岛争议与中日关系面临的挑战

内容提要: 2012 年是中日邦交正常化 40 周年,两国关系非但没有改善,反而由于日本政府 “购买”钓鱼岛而急剧恶化。钓鱼岛领土主权争议问题,已成为中日关系面临的最大问题。中日关系正处在新的历史十字路口,出现“政冷经凉”趋势,面临相当

转载 与NBA球星关系暧昧的名模图 nba2k online刷球星

原文地址:与NBA球星关系暧昧的名模(图)作者:艾尔斯第一:名模丹尼斯-米兰妮生于欧洲但住在美国,其独具欧洲风情的相貌、腰细臀圆,但最让人侧目的,始终是她超乎常人的胸围数字。身材火爆、笑容甜美的丹尼斯-米兰妮在2007年的比基尼小姐大赛中

声明:《格兰杰因果关系检验的SAS实现 eviews格兰杰因果检验》为网友拽天下分享!如侵犯到您的合法权益请联系我们删除