Hi to all. First I am just begginer to SAS and to understand SAS complex macros and terms is very hard at this point. I am replicating a financal Table 1 & Table2 of [Avramov, Doron, and Tarun Chordia, 2006 “Asset Pricing Models and Financial Market Anomalies,”] To measure momentum, they used monthly accumulated returns of (previous) last 2nd & 3rd (Ret23), 4th to 6th (Ret46), and 7th to 12th (Ret712) months. Data itself is panel data in which I have firms (permno) monthly data for several years along with returns, BM, size and turnover. I have attached "merge1" file which I am using for generating returns. First I tried to use a simple macro code which take logs, then do sum, and convert back to exp. Everything seems fine with codes but my results have totally different values and trends ( it should be Ret712>Ret46>Ret23) . here are the codes I used initially. By using both option 1 and 2 did'nt improve anything. proc sort data=merge1 ; by permno descending date; run;
%macro calcret;
data merge2;
set merge1;
by permno;
lret=log(ret+1); * Take natural logs of the firm return (ret);
array lagret[12] lagret1-lagret12;
%do j=1 %to 12; * Macro "do-loop" to create the 12 lags;
lagret&j=lag&j(lret);
%end;
* Calculate the cumulative returns by adding the lags of the returns;
* Option 1;
ret23= (exp( sum(of lret lagret2-lagret3)) -1)*100;
ret46= (exp( sum(of lret lagret4-lagret6)) -1)*100;
ret712= (exp( sum(of lret lagret7-lagret12)) -1)*100;
*Option 2;
sret23= ((exp( sum(lagret2,lagret3)))-1)*100;
sret46= ((exp( sum(lagret4,lagret5,lagret6))) -1)*100;
sret712=((exp( sum(lagret7,lagret8,lagret9,lagret10,lagret11,lagret12)))-1)*100;
drop l: count i rf; * Drop unnecessary variables;
%mend calcret; * End of macro;
%calcret; * Run the macro; Now after many attempts and searches, I am planning to try doing the same thing with PROC EXPAND. But I have two issues. 1: Proc Expand backward moving Average/Sum include current and previous values. Is there anyway to accumulate/add/sum only previous values, i.e. starting from t-2 to t-3 (not t to t-3) and accumulated return from t-4 to t-6 (not t to t-6).. 2: Also is it ok to just add (sum up) the return to get accumulated return (which I doubt, bcoz returns are either should be multiplied or converted to natural log before adding. Please give some suggestion) 3: In Proc Expand Chapter on SAS guide, there is this function which seems to do similar thing, as I did above in macro codes. proc expand data=a out=b from=month to=week;
id date;
convert sales / observed=total
transformin=(log)
transformout=(exp);
run; Can this code be modified to get summ of required return by taking (Log) of IN values and then transforming OUT values as (Exp) function? Lastly, I am not sticking to any particular approach. If you have any other way to calculate accumulated returns, please advise me. I tried best to explain everything is details. If I missed anything, plz feel free to ask. Once again thanks alot in advance.
... View more