LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2012, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
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
Comments: To: "David L. Cassell" <davidlcassell@MSN.COM>

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 http://www.sas-programming.com/2011/08/rolling-analysis-of-time-series.html?utm_source=BP_recent

or tinyurl at : http://tinyurl.com/6rajw2o

this is the not the fastest way but a good balance between speed and easy to code/understand

On Fri, 20 Apr 2007 17:56:21 -0700, David L Cassell <davidlcassell@MSN.COM> wrote:

>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. > >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 >involving SAS/ETS. > >P.S. I have not sat down and tried it, but there is probably a PROC EXPAND >solution that would be cleaner. > >HTH, >David >-- >David L. Cassell >mathematical statistician >Design Pathways >3115 NW Norwood Pl. >Corvallis OR 97330 > >_________________________________________________________________ >Need a break? Find your escape route with Live Search Maps. >http://maps.live.com/?icid=hmtag3


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