我想要计算股指累计60个月的收益率,用了以下的宏,但是2016年1月也有数值,我不知道是否这个程序有问题,或者应该怎么理解我跑出来的结果,求大神指教~
%macro calcret;
data paper.IDX_Idxtrdmth1;
set paper.IDX_Idxtrdmth1;
by indexcd;
/* Take natural logs of the index return (idxrtn) */
lidxrtn=log(idxrtn+1);
/* Define arrays to create the lagged values */
array lagidxrtn[59] lagidxrtn1-lagidxrtn59;
/* This is the macro portion: a "do-loop" to create the 59 necessary lags */
%do j=1 %to 59;
lagidxrtn&j=lag&j(lidxrtn);
%end;
/* The following statements set to missing lagged values that */
/* are reading the data corresponding to the previous idxcd */
if first.indexcd then count=1;
do i=count to 59;
lagidxrtn
= .;
end;
count +1 ;
/* Calculate the cumulative returns by adding the logs of the returns*/
idxcumret= exp( sum(of lidxrtn lagidxrtn1-lagidxrtn59)) -1;
/* Drop unnecessary variables */
drop l: count i;
%mend calcret; /* End of macro */
%calcret; /* Run the macro */