/* HPFILTER First Draft : December 21, 1989 by Ken Matheny (hodpres()) Second Draft: August 3, 1994 by Simon van Norden (hpfilter()) Third Draft : April 27, 1995 by Robert Vigfusson (hpfilter()) This program is designed to smooth the stochastic series y by use of the Hodrick-Prescott method mentioned in footnotes of the Kydland & Prescott "Time to Build" paper, and Hansen's "Indivisible Labor" paper. The method involves minimizing an expression containing the squared differences between the actual and smoothed series, and terms involving the differences between successive elements of the smoothed series. This leads to a linear filter for the original data. "w" is a smoothness parameter. The larger w, the smoother the resulting series, shp. Kydland and Prescott suggest a "w" of 1600 for quarterly data. FORMAT : {s} = hpfilter(y,w); INPUTS : y : The series to be filtered; w : The smoothness parameter (suggest 1600). OUTPUT : shp: The smoothed series. The deviations can be calculated simply as (y-shp). SOURCE : hpfilter.arc */ proc(1) = hpfilter(y,w); local t,a,b,c,d,m,i,j,shp; t = rows(y); a = 6*w+1; b = -4*w; c = w; d = c~b~a; d = ones(t,1)*d; d[1,1]=0; d[2,1]=0; d[1,2]=0; d[2,2] = -2*w; d[t,2] = -2*w; d[1,3] = 1+w; d[t,3] = 1+w; d[2,3]=5*w+1; d[t-1,3]=5*w+1; @ The Smoothed Series @ shp = bandsolpd(eye(t),d)*y; retp(shp); endp;