LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (April 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 16 Apr 2007 14:45:41 -0400
Reply-To:     Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject:      Re: SAS Macro qn/rolling regression

I've tried to complete it, but I saw another solution without a macro loop! I think there are too much iterations for a macro loop, better rearrange the data and use BY processing. I cannot try it out, because I don't have STAT and therefor your macro doesn't run here.

options nocenter;

data try;

set data.allfunds;


proc datasets lib=work;

delete final_roll_est_rsq;


options mprint;

%macro rollingreg(data=try , regn=36 , totn=11236, outname= );

%do i= &regn %to &totn;

data _null_;

x=&i - &regn +1;

call symput('start',trim(left(x)));


data temp;

set &data(firstobs=&start obs=&i) end=eof;

if eof then rp=.;

run; /*proc print data=temp; run; */

ods select none;

/* use OUTEST= and ADJRSQ options */

proc reg data=temp outest=rsq(keep=Intercept smb hml rref indrf umd _RSQ_ _ADJRSQ_) adjrsq; model rp= smb hml rref indrf umd ds ts dy;

run; quit;

data rsq;

set rsq;




/*ods select all; proc print data=rsq; run; */

proc append base=&outname data=rsq;


%end; %mend;

%rollingreg(data=try, regn=36 , totn=11236 );

ods select all; proc print data=final_roll_est_rsq; *proc means;*var _rsq_ _adjrsq_; run;

%macro doit;

proc sort nodupkey force data=data.allfunds(keep=icdi_no) out=dummy;

by icdi_no;


%let id_no=0;

data _null_;

set dummy;

call symput("id_no",_n_);

call symputx("id"!!compress(put(_n_,8.)),icdi_no);



%do n=1 %to &id_no;


%end; ;

set data.allfunds;

%do n=1 %to &id_no;

if icdi_no="&&id&n" then output d&n;



%do n=1 %to &id_no;

data _null_;

set d&n nobs=no;

call symput("obs&n",no);



%rollingreg(data=d&n , regn=36 , totn=&&obs&n, outname=out&n );





On Mon, 16 Apr 2007 04:26:45 -0400, Abhay Kaushik <abhaykaushik@HOTMAIL.COM> wrote:

>Hi All >I am analyzing the performance of 1430 mutual funds. It is a time >series and I need to estimate intercepts of this time series using a >window of 36 observations. This means 1 to 36 regression and then >regression on observation 2 to 37 and so on. Each fund has its >identification number (icdi_no) and date (caldt). It is a time series >where observations for each fund are stacked over each other and >different fund may have different number of observations. For example >Fund 1 has 100 monthly observations starting period lets say Jan 1990 >and end period is April 1998 and then Fund 2 observations start and it >may have 120 observations and so on. I have dependent variable (Y) and >explanatory variables X1, X2 and so on for each fund for each given >date. For each ID, I need to run "rolling window" regressions, where >the "rolling window" is 36 observations long. That is, for each >icdi_no, I need to run a regression using observations 1 to 36, a >regression using observations 2 to 37, a regression using observations >3 to 38,...., a regression using the last 36 observations available for >that icdi_no. >I need to store parameters of each rolling window regression of >each "icdi_no" along with corresponding "caldt" (of last observation for >example for 1st reg it is 36th and second it is 37th) into a single >dataset, since I need to use them for further regressions. >I have 1400+ firms in my data; I want to create a loop or string in that >program in a way that SAS reads data by icdi_no and once first icdi_no >observations are finished it goes to second icdi_no and run the similar >roll regression. >Following codes that I am using work fine but this program is only able to >give me rolling estimates for only one fund at a time and do not tell me >the icdi_no and corresponding caldt. > >My program is: > >libname data "c:\e1\sf"; >options nocenter; >data try; >set data.allfunds; >run; >proc datasets lib=work; > delete final_roll_est_rsq; >run; >options mprint; >%macro rollingreg(data=try , regn=36 , totn=11236 ); >%do i= &regn %to &totn; > >data _null_; > x=&i - &regn +1; > call symput('start',trim(left(x))); >run; > >data temp; > set &data(firstobs=&start obs=&i) end=eof; > if eof then rp=.; >run; > /*proc print data=temp; >run; */ >ods select none; > > /* use OUTEST= and ADJRSQ options */ >proc reg data=temp > outest=rsq(keep=Intercept smb hml rref indrf umd _RSQ_ _ADJRSQ_) adjrsq; > model rp= smb hml rref indrf umd ds ts dy; >run; >quit; > >data rsq; set rsq; > firstobs=&start; > lastobs=&i; >run; > > /*ods select all; >proc print data=rsq; >run; */ > >proc append base=final_roll_est_rsq data=rsq; >run; > >%end; >%mend; > >%rollingreg(data=try, regn=36 , totn=11236 ); > >ods select all; >proc print data=final_roll_est_rsq; >*proc means;*var _rsq_ _adjrsq_; >run; > > >I need a) >to include all the funds in that program and able to get output >containing both the id and corresponding date of those estimates. > >Any help is extremely appreciated.

Back to: Top of message | Previous page | Main SAS-L page