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;
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.