The sas code presented below tries to set up for a fixed 12-month estimation ‘window’ that increments forward one month
for each iteration of the loop until it reaches the end of a full sample period. The program has to construct windows for every mutual fund identified by crsp_fundno variable. To simplify the program my data set test_persistance1 containing four variables (crsp_fundno , datem, mret, and rmex), sorted by crsp_fundno and datem. My date variable is saved as a numeric variable ( its format is best.12).
The code works but unfortunately does not give me the desired result. I attached two screenshots to better explain the problem.
Thank you for helping.
DATA Test_win / view=Test_win ;
array _X {12} _temporary_ ;
array _Y {12} _temporary_ ;
set test_persistance1;
by crsp_fundno ;
retain N 0;
N = ifn(first.crsp_fundno,1,N+1);
I=mod(N-1,12)+1;
_X{I}=rmex;
_Y{I}=mret;
if N>=12 then do I= 1 to 12;
rmex=_X{I};
mret=_Y{I};
output;
end;
run;
proc reg data=Test_win noprint outest=results;
by crsp_fundno datem;
model mret=rmex;
quit;
The data contains more than 2500 mutual funds.
The structure of my dataset is as following:
Datem crsp_fundno RMEX mret
where crsp_fundno is the fund’s identifier, datem is in BEST12. format, RMEX is the market return and mret is the mutual fund return. datem range from 201201 to 201612.
The idea is to design a rolling sample period. In my case, each subsample is 12 months in length and the windows move ahead 1 month per loop. 201201-201212 (subsample 1), 201202-2013-01 (subsample 2), and so on. This procedure must be applied fund by fund.
Once this step is successful, the regressions can be conducted by datem and crsp_fundno.
The second attachment, which seems to open, shows that the result obtained is incorrect.
Thank you!
Dear sas community,
Since I still have no answers, I reformulate the problem with the following diagrams.
Output desired:
201201
201202 201202
. . 201203
. . . etc.
. . .
201212
201301
201302 201601
.
.
.
201612
This scheme must be done for each fund.
Output obtained:
201201
201202 201301
. 201202 201301 201301
. . 201202 201202
. . .
201212
201212
201212 201212
N=12 N=13 N=14 ………………………………………… N=23
Then,
201301
201302 201401
. 201302 201401 201401
. . 201302 201302
. . .
201312
201312
201312 201312
N=24 N=25 N=26 …………………………………………N=35
And so on.
I forgot to mention that the funds do not all have the same longevity.
For more clarity concerning the data, I attach a SAS file that contains the data of only two funds to simplify things.
In the hope of finding a solution, I want to thank you for your time.
Google turns up a number of papers on this topic with actual code.
Search for:
sas "rolling regressions"
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.