BookmarkSubscribeRSS Feed
GHALI
Calcite | Level 5

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;

4 REPLIES 4
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

pictures are not worth a 1000 words nor do they have the value of data in the form of a SAS datastep.

your @GHALI second attachment is black for what I see.

 

@GHALI thank you for updating the attachments which now open and display information.

 

 

GHALI
Calcite | Level 5

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!

GHALI
Calcite | Level 5

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.

PaigeMiller
Diamond | Level 26

Google turns up a number of papers on this topic with actual code.

 

Search for:

sas "rolling regressions"

--
Paige Miller

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1255 views
  • 0 likes
  • 3 in conversation