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
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
Thank you. I'll look more closely at the proc ucm.
Best regards,
Chris
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.