BookmarkSubscribeRSS Feed
chris2377
Quartz | Level 8

Dear all,

I have a following problem.

I would like to calculate a trend for some ratio, using one-sided Hodrick-Prescott  filter.  This means, I want to use rolling window and calculate the trend using only the data available up to the given period.  For example

data have;

format period ddmmyy10.;

input period ddmmyy10. ratio;

datalines;

31/03/2000        7.7035308

30/06/2000        7.704633

30/09/2000        7.7113104

31/12/2000        7.7438095

31/03/2001        7.7623468

;

run;

In the output dataset I would like to have another variable with the trend for the ratio, where for the first period the trend is equal to the first value of the ratio (7.7035308), for the second period it is calculated on the basis of the first and the second value of the ratio (7.7035308 and 7.704633 respectively), for the third period – on the basis of the  first, second and third value etc.

In the next step, I would like to do the same, but separately for each country A and B, using a panel dataset. For example

data have1;

format period ddmmyy10.;

input period :ddmmyy10. country :$1. ratio ;

datalines;

31/03/2000        A            7.7035308

30/06/2000        A            7.704633

30/09/2000        A            7.7113104

31/12/2000        A            7.7438095

31/03/2000        B            7.8334211

30/06/2000        B            7.8389886

30/09/2000        B            7.8344153

31/12/2000        B            7.8422493

31/03/2001        B            7.8409916

30/06/2001        B            7.8572007

;

run;

Again, I want to add another variable to the dataset with rolling HP trend, but calculated separately for country A and B.

Any ideas how to do this? I've looked at the proc timeseries but haven't found any option to include rolling window or set number of observations to be used to calculate the trend.

Best,

Chris

2 REPLIES 2
rselukar
SAS Employee

Hello Chris,

You can use the following program (based on PROC UCM in SAS/ETS):

proc ucm data=have;

   id period interval=qtr;

   model ratio;

   irregular ;

   level var=0 noest print=filter;

   slope var=0.000625 noest;

   estimate PROFILE;

   forecast ;

run;

For more information see the UCM procedure documentation, particularly the example number 5(Trend Removal Using the Hodrick-Prescott Filter):

SAS/ETS(R) 13.2 User's Guidehttp://support.sas.com/documentation/cdl/en/etsug/67525/HTML/default/viewer.htm#etsug_ucm_examples05...

The FORECAST variable in the output data set FOR contains the one-step-ahead forecasts of RATIO that

you are looking for.  Forecasts for first two quarters are missing by design because the first two observations

are needed for "initialization" (you can set them to some convenient values if you choose).

From third quarter on, the forecasts are one-sided Hodrick-Prescott filter based.  For your second example,

you can use the same program with COUNTRY as a BY variable (you will need to sort your data by

COUNTRY and PERIOD).


Hope this helps.

Rajesh

chris2377
Quartz | Level 8

Thank you. I'll look more closely at the proc ucm.

Best regards,

Chris

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 2 replies
  • 2209 views
  • 0 likes
  • 2 in conversation