BookmarkSubscribeRSS Feed
riccardo85
Calcite | Level 5

Recursive regression is a basic tool in linear statistical models

Many standard handbook include this topic (e.g. coefficient stability in time series regression)

It wouldn't be difficult to create by SAS programmers a proc RECREG (!) with the basic output.....saving a lot of client time & effort

thank you

 

12 REPLIES 12
ballardw
Super User

Is this a question or a suggestion?

There is a specific part of the forum for Suggestions

riccardo85
Calcite | Level 5

where is it?

Ksharp
Super User
It is under PROC ARIMA , it is also called dynamic regression.
Better post it at Forecast forum .

riccardo85
Calcite | Level 5

For me recursive regression means

<<Using the K first observations in the sample to get an initial estimate
of beta vector, we gradually enlarge the sample, adding one observation at a time, and
re-estimate beta at each step >> (Dufour, J. of econometrics, 19, 1982,  pp.31-76)

 

Sas has something similar in proc AUTOREG only

Thank you

 

 

 

Ksharp
Super User
Maybe PROC IML could do it.
Post it at IML forum, and @Rick_SAS might help you .

riccardo85
Calcite | Level 5

thank you but why not create an option (by SAS programmers) in proc REG? most of the machinery is in proc AUTOREG....

Ksharp
Super User
It is timer series analysis, unlike the traditional regression analysis.
obs to obs is correlation for time series, but they are supposed to be uncorrelation for regression analysis.

PROC IML is a statistical analysis language which can achieve many customize or self-define statistical method.
  
riccardo85
Calcite | Level 5

I take your point.

proc IML could be a second best solution (but a subroutine for time series recursive regression doesn't exist at the moment)

however, in my opinion, the first best would be a "recursive" option in proc ARIMA

 

 

Yamani
Obsidian | Level 7

Hello,

 

I want to run recursive regression. My data spans the period from October 1997 to August 2017.

The following code allows me to run the rolling regression (not the recursive regression).

In particular, the following code DROPS earlier observations as additional observations become
available.

 

However, I need to adjust the following code so that KEEPS earlier observations and adding an observation to the end of the sample with every run of the regression.

 

Here is the code:

 

 

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;


data developedrankdates (drop=firstdate lastdate);set developedrankdates;date=rankdate;
i=1;do while(i<=131);output;  *131 is the window width;
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;

Thanks in advance

Yamani
Obsidian | Level 7

Hello All,

 

I want to run recursive regression. My data spans the period from October 1997 to August 2017.

The following code allows me to run the rolling regression (not the recursive regression).

In particular, the following code DROPS earlier observations as additional observations become
available.

 

However, I need to adjust the following code so that KEEPS earlier observations and adding an observation to the end of the sample with every run of the regression.

 

Here is the code:

 

 

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;


data developedrankdates (drop=firstdate lastdate);set developedrankdates;date=rankdate;
i=1;do while(i<=131);output;  *131 is the window width;
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;

Thanks in advance

 

ChrisNZ
Tourmaline | Level 20

Your goal is unclear. You have a long succession of steps, many of which don't do much at all.

Give us an example with 2 countries and a 5-day window, 10 days' data, and show us the starting data and the desired outcome.

Yamani
Obsidian | Level 7

Thanks for your reply.

********************************************************* Data Set *****************************************

 

* My dataset is panel monthly data with 10 countries

* Sample period: From December 1996 to August 2017.

 

Here is an example to show my data set.

Date                  Country     Y       X      Number      Observation

12/31/1996       Australia                           1                   1

01/31/1997      Australia                            1                   2

......

.....

.....

08/31/2017     Australia                              1                   250

12/31/1996     Canada                               2                   1

........

.......

08/31/2017     Australia                              2                  250

......

.....

......

12/31/1996     UK                                      10                   1

.......

......

......

08/31/2017     UK                                      10                   250

 

************************************ Goal: Run Recursive Regression ************************************

 

* I want to run several recursive regressions for EACH country (i.e. keeps the starting date (i.e., December 1996) fixed,

and then adding an observation to the end of the sample with every run of the regression).
More specifically:

- the first regression is run with data from December 1996 to August 2008,

- the second regression is run with data from December 1996 to September 2008,

- the third regression is run with data from December 1996 to October 2008,

...........................

........................

........................

- the last regression is run with data from December 1996 to August 2017.

 

I was thinking to create a new date variable (call it Rankdate) that shows the ending date in each recursive regression, as follows:

    Rankdate                     Date             Country     Y       X       Number      Observations

 August 2008             12/31/1996       Australia                            1                   1

 August 2008              01/31/1997      Australia                            1                   2

......

August 2008               08/31/2008      Australia                           1                 141

September 2008         12/31/1996       Australia                          1                 142

.....

September 2008         09/30/2008     Australia                              1                 283

...................

.....................

August 2017                  12/31/1996       Australia                          1 

............

August 2017                  08/30/2017       Australia                          1               

August 2008                  12/31/1996        Canada                             2                   1

........

.......

                                  

......

.....

......

August 2017            08/31/2017                   UK                            10

 

After having the above dataset, I can easily run PROC REG or PROC PANEL by RANKDATE and by COUNTRY.

 

My problem, however, is how to create the above data set.

 

Thanks for your help in advance.                                                  

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 2970 views
  • 0 likes
  • 5 in conversation