Date: Mon, 2 Jan 2012 14:42:14 -0500
Reply-To: oloolo <dynamicpanel@YAHOO.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: oloolo <dynamicpanel@YAHOO.COM>
Subject: Re: SAS Macro qn/rolling regression
Yes, using PROC EXPAND to built up every elements in the SSCP matrix and
then apply PROC REG.
See Method 2.) (the third solution) at
or tinyurl at : http://tinyurl.com/6rajw2o
this is the not the fastest way but a good balance between speed and easy to
On Fri, 20 Apr 2007 17:56:21 -0700, David L Cassell <davidlcassell@MSN.COM>
>>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
>>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
>>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";
>>proc datasets lib=work;
>> delete final_roll_est_rsq;
>>%macro rollingreg(data=try , regn=36 , totn=11236 );
>>%do i= ®n %to &totn;
>> x=&i - ®n +1;
>> call symput('start',trim(left(x)));
>> set &data(firstobs=&start obs=&i) end=eof;
>> if eof then rp=.;
>> /*proc print data=temp;
>>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;
>>data rsq; set rsq;
>> /*ods select all;
>>proc print data=rsq;
>>proc append base=final_roll_est_rsq data=rsq;
>>%rollingreg(data=try, regn=36 , totn=11236 );
>>ods select all;
>>proc print data=final_roll_est_rsq;
>>*proc means;*var _rsq_ _adjrsq_;
>>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.
>1. You have already been told how to turn this into a by-processing
>problem. That's going to be WAAAAY faster than doing this in a macro
>loop in a thousand separate steps.
>2. That may still be the wrong thing to do. You have time series
>data. You have multiple firms per year. That makes this a panel-data
>problem. I don't see anything in your code that addresses the nature of
>your problem or of your data. Your point estimates may be really
>lousy, due to the autocorrelation of the data and/or due to the
>cross-correlation structure you have.
>I'm a lot more concerned about #2 here, since if you took a couple days to
>get the right answers, you would still be in good shape. But I think you
>are possibly getting *bad* answers.
>Please write back to SAS-L (not to me personally, unless you want to hire
>me as a consultant) and explain *why* you are doing this, and what your
>larger goal is. There is likely to be a much better approach, probably
>P.S. I have not sat down and tried it, but there is probably a PROC EXPAND
>solution that would be cleaner.
>David L. Cassell
>3115 NW Norwood Pl.
>Corvallis OR 97330
>Need a break? Find your escape route with Live Search Maps.