data want;
set have;
by permno ;
obs+1;
if first.permno then obs=1;
array ret_hist{0:59} _temporary_;
if obs>=61 then do;
sk=skewness(of ret_hist{*});
output;
end;
ret_hist{mod(obs,60)}=return;
run;
This calculates lagged skewness for every window of size 60, by applying the skewness function against a 60-element history of returns. The array RET_HIST contains returns for date{i-60} through date{i-1}. Only after skewness is calculated is the history updated with returns for date{i} (replacing returns of date{i-60}). This establishes an array for dates{i-59} through date{i}, ready for the next incoming obs.
The program is slightly inefficient since each skewness is calculated from scratch. One could calculate skewness of a window from (a) skewness of the previous windows and the returns from the (b) new return in the window (actually the return for date{i-1}) and the (c) dropped return (for date{I-61}). Come back to us if you need that efficiency, although I doubt it would make that much difference.
... View more