/* HP - Hodrick - Prescott Filter by M. Watson, 1991 Usage: xp = HP(x,l) where: x = NxK matrix of K series of length N to be filtered; l = smoothness parameter (1600 for quarterly data); xp = NxK matrix of K series of length N representing the percentage deviations of each of the original series in x from their trend. Note: if you want the trend, change the next to last line to: retp(xt); if you want the smoothed series, use retp(xd). */ proc HP(x,l); local j,xd,xt,i,k,ty,cy,n,xhp,q,a; n=rows(x); j=1; a=zeros(n-2,n); do until j>n-2; a[j,j]=1; if j+1 le n; a[j,j+1]=-2; endif; if j+2 le n; a[j,j+2]=1; endif; j=j+1; endo; i=eye(n); xd=zeros(rows(x),cols(x)); xt=xd; xhp=xt; k=1; do until k>cols(x); ty=solpd(x[.,k],i+l*a'a); cy=x[.,k]-ty; xd[.,k]=cy; xt[.,k]=ty; k=k+1; endo; xhp=xd./xt*100; retp(xhp); endp; function [s]=hpfilter(y,w) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Author: Ivailo Izvorski, % Department of Economics % Yale University. % izvorski@econ.yale.edu % This code has been used and seems to be free of error. % However, it carries no explicit or implicit guarantee. % % function [s]=hpfilter(y,w) % Hondrick Prescott filter where: % w - smoothing parameter; w=1600 for quarterly data % y - the original series that has to be smoothed % s - the filtered series %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if size(y,1)