BookmarkSubscribeRSS Feed
Yamani
Obsidian | Level 7

 

Hello All,

 

I use the following code to forecast using rolling windows. The following code works fine with me. The code gives me the forecast for each rolling window in my sample (i.e., several forecasts for each rolling window)

 

However, my question is that, to my understanding, I have to report the results only for one model with the least squared errors. I don't know how to do this! I don't know the code for Clark and West test! Any help will be appreciated. Thanks in advance.

 

Here is the code:

 

**** (2) Out-of-Sample forecasts with rolling regressions from September 2008 to August 2017 *************;
* We generate forecasts using a rolling window (which drops earlier observations as additional observations become
available. In sample period: December 1996 to August 2008 and out-of-sample period of September 2008 to August 2017;

 

*(2.1) Creating the rolling windows;
** Developed Countries Sample;
data developed (drop=obs);set ma.developed; format date DATE9.;run;
data developed;set developed; where ('31Oct97'd <= date <= '31Aug17'd); format date DATE9.;run;

*Counting number of observations & Assigning numbers for developing countries;
*** Counting number of observations;
data developed;set developed; Obs+1; if country ne lag(country) then Obs=1; run;
proc sort data=developed (keep=country Obs) out=Numberdeveloping noduplicates; by country Obs; run;
** Assigning numbers for different countries;
data Numberdeveloped;set Numberdeveloped; by country Obs; if last.country then output; run;
data Numberdeveloped;set Numberdeveloped;Number=_n_;run;
data developed;merge developed (drop=Obs) Numberdeveloped; by country;run;

data firstandlastdates;set developed(keep=country date);by country; retain firstdate;
date=intnx('month', date, 1)-1; *this function Increments a date value by a given interval;
if first.country then firstdate=date;
if last.country then do;lastdate=date;output;end;run;

data firstandlastdates;set firstandlastdates;format firstdate DATE9.;format lastdate DATE9.;run;

* Then, create a complete list by filling in the inbetween dates;
data developedrankdates(rename=(date=rankdate));set firstandlastdates;date=firstdate;
do while(date<=lastdate);output;
date=intnx('month', date+1, 1)-1;end;run;

*In-sample period of December 1997 to December 2013
*For each rankdate, I then get the list of the 24 dates from which that rankdate will use data.
* The goal is to create a dataset containing ``rankdates'', which are the date identifiers for the rolling regression.
A rankdate of 31Dec1997, for instance, uses data from 31Dec1997 to 30Nov1999, inclusive;
data developedrankdates (drop=firstdate lastdate);set developedrankdates;date=rankdate;
i=1;do while(i<=131);output;
date=intnx('month', date, 0)-1;
i=i+1;format date DATE9.;end;run;

data developedrankdates;set developedrankdates;where ('30Aug08'd <= rankdate);run;

*Once we have this, all we need to do is merge it with the returns;
data ret;set developed(keep=country date return MA);where return is not missing;
date=intnx('month', date, 1)-1;run;

proc sort data=ret;by date country;run;

proc sort data=developedrankdates;by date country;run;
data developedrankdates;merge countryrankdates(in=a) ret(in=b);by date country;
if a and b;run;
proc sort data=developedrankdates; by country rankdate;run;
*Notice that I merged by date, not rankdate.
And now all that remains is to run the regressions;

 

*(2.2) Out-of-sample forecasts;

PROC UCM DATA = developedrankdates; BY rankdate;
ID DATE INTERVAL=MONTH;
MODEL RETURN = MA;
IRREGULAR;
level var=0;
estimate back=0 outest=ma.est;*The default is BACK=0,
which means that the forecast starts at the end of the available data;
FORECAST back=0 LEAD=1 outfor=ma.results plot=forecasts;
*forecast span;*This reports the one-step ahead out-of-sample forecast;
RUN;

1 REPLY 1
Puwang
Obsidian | Level 7

You can follow the instructions on the site http://support.sas.com/kb/42/514.html to download a sas macro %Vuong. This macro basically implement Vuong and Clarke tests for comparing nested and nonnested models.

 

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1103 views
  • 1 like
  • 2 in conversation