Date: Mon, 16 Apr 2007 06:27:52 -0700
Reply-To: shiling99@YAHOO.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Shiling Zhang <shiling99@YAHOO.COM>
Organization: http://groups.google.com
Subject: Re: SAS Macro qn/rolling regression
In-Reply-To: <200704160826.l3FAmpD2020586@malibu.cc.uga.edu>
Content-Type: text/plain; charset="iso-8859-1"
On Apr 16, 4:26 am, abhaykaus...@HOTMAIL.COM (Abhay Kaushik) 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= ®n %to &totn;
>
> data _null_;
> x=&i - ®n +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.
A macro will work in this case but it will be very slow in term of the
number of regressions(1430*65). I would suggest to re-assemble you
data as below and to use by statement. It will run super fast.
Note: the following sample simulation is just for one 'fund' with 100
obs. You may modify as needed for your problem.
HTH
data t1;
do date='1jan2006'd to '1jan2006'd+99;
x=rannor(12345);
y=3+2*x+rannor(12345);
output;
end;
format date yymmdd10.;
run;
data t2;
do i = 1 to 65;
do j = i to i+35;
set t1 point=j;
rolling_index=i;
output;
end;
end;
stop;
run;
proc reg data=t2 outest=est noprint;
by rolling_index;
model y=x;
run;
quit;
proc print data=est;
run;
|