tsfiltering beamer

56
Introduction Theory of time-series filtering Stata filtering routines Empirical illustrations Time-series filtering techniques in Stata Christopher F Baum Department of Economics, Boston College July 2006 Christopher F Baum Time-series filtering techniques in Stata 1

Upload: shuchi-goel

Post on 15-Sep-2015

279 views

Category:

Documents


5 download

DESCRIPTION

Filtering techniques

TRANSCRIPT

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Time-series filtering techniques in Stata

    Christopher F Baum

    Department of Economics, Boston College

    July 2006

    Christopher F Baum Time-series filtering techniques in Stata 1

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Introduction

    There are several time-series filters commonly used inmacroeconomic and financial research to separate the behavior of atimeseries into trend vs. cyclical and irregular components. Thesetechniques can usually be expressed in terms of linear algebra, andreliable code exists in other matrix languages for theirimplementation.

    I briefly describe the concept of time-series filtering, and thenpresent several new implementations of time-series filters for Statausers written in Mata. These routines avoid matrix size constraintsand are much faster than previous versions translated from Fortranwritten in the ado-file language.

    Christopher F Baum Time-series filtering techniques in Stata 2

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Introduction

    There are several time-series filters commonly used inmacroeconomic and financial research to separate the behavior of atimeseries into trend vs. cyclical and irregular components. Thesetechniques can usually be expressed in terms of linear algebra, andreliable code exists in other matrix languages for theirimplementation.

    I briefly describe the concept of time-series filtering, and thenpresent several new implementations of time-series filters for Statausers written in Mata. These routines avoid matrix size constraintsand are much faster than previous versions translated from Fortranwritten in the ado-file language.

    Christopher F Baum Time-series filtering techniques in Stata 3

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Theoretical background

    The concepts of filtering in econometrics have been borrowed fromthe engineering literature. Linear filtering involves generating alinear combination of successive elements of a discrete-time signalxt , as represented by

    yt = (L)xt =j

    jxtj

    where L is the lag operator, equivalent to Statas time-seriesoperator L. The sequence

    (L) = { + 1L1 + 0 + 1L+ . . . }

    is the linear filter, and defines the response to an input signal inthe form of a unit impulse.

    Christopher F Baum Time-series filtering techniques in Stata 4

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Moving average filters

    The sequence of filter weights (L) can be finite or infinite. Afinite sequence is described as a moving average filter or a finiteimpulse-response (FIR) filter. When the filter produces an impulseresponse of an indefinite duration, it is called an infiniteimpulse-response (IIR) filter. If all of the filter weights areassociated with non-negative powers of L, the filter is known ascausal or backward-looking.

    We often consider finite moving average processes in working witharima models. As is well known, a finite moving average or MA(q)process has finite memory: only the last q periods of the xsequence affect the output of the filter, or as we would describeit, the response variable y .

    Christopher F Baum Time-series filtering techniques in Stata 5

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Moving average filters

    The sequence of filter weights (L) can be finite or infinite. Afinite sequence is described as a moving average filter or a finiteimpulse-response (FIR) filter. When the filter produces an impulseresponse of an indefinite duration, it is called an infiniteimpulse-response (IIR) filter. If all of the filter weights areassociated with non-negative powers of L, the filter is known ascausal or backward-looking.

    We often consider finite moving average processes in working witharima models. As is well known, a finite moving average or MA(q)process has finite memory: only the last q periods of the xsequence affect the output of the filter, or as we would describeit, the response variable y .

    Christopher F Baum Time-series filtering techniques in Stata 6

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    If our interest is in computing moving averages, we often employ acentered moving average: that is, one that includes several leadsand lags. A 5-term moving average uses two leading values, thecurrent value, and two lagged values to generate the averagedseries.

    See tssmooth ma or the egen function filter from Coxsegenmore package for implementations of the moving averagefilter, centered or uncentered. In an uncentered filter, we use onlylagged values in a moving average filter, allowing computation ofthe averaged series through the last available observation.

    Christopher F Baum Time-series filtering techniques in Stata 7

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    If our interest is in computing moving averages, we often employ acentered moving average: that is, one that includes several leadsand lags. A 5-term moving average uses two leading values, thecurrent value, and two lagged values to generate the averagedseries.

    See tssmooth ma or the egen function filter from Coxsegenmore package for implementations of the moving averagefilter, centered or uncentered. In an uncentered filter, we use onlylagged values in a moving average filter, allowing computation ofthe averaged series through the last available observation.

    Christopher F Baum Time-series filtering techniques in Stata 8

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Smoothers

    Official Stata contains a number of other routines to smooth andforecast univariate time-series data, as described in [TS]tssmooth. These include several recursive smoothers (exponential,double exponential, and HoltWinters with and without seasonaladjustments) as well as a nonlinear filter which applies [R]smooth, a robust nonlinear smoother to the time series.

    As the manual entry indicates, the moving average and nonlinearfilter routines are generally used to extract the trend from a timeseries while omitting the high-frequency or noise components. Ifyou are interested in those latter components, they may berecovered as the difference between the original series and thesmoothed series.

    Christopher F Baum Time-series filtering techniques in Stata 9

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Smoothers

    Official Stata contains a number of other routines to smooth andforecast univariate time-series data, as described in [TS]tssmooth. These include several recursive smoothers (exponential,double exponential, and HoltWinters with and without seasonaladjustments) as well as a nonlinear filter which applies [R]smooth, a robust nonlinear smoother to the time series.

    As the manual entry indicates, the moving average and nonlinearfilter routines are generally used to extract the trend from a timeseries while omitting the high-frequency or noise components. Ifyou are interested in those latter components, they may berecovered as the difference between the original series and thesmoothed series.

    Christopher F Baum Time-series filtering techniques in Stata 10

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    The effects of linear filtering

    Application of a linear filtereither FIR or IIRwill affect thecyclical components of a time series, and is often studied in thefrequency domain rather than the time domain. The filter is liableto alter the amplitude of any cyclical component. This effect variesaccording to the frequency of the component, and is described asthe gain of the filter.

    The concept is familiar to anyone who uses a stereo: the treblecontrol strengthens or weakens the high frequencies of yourfavorite tune, while the bass control affects the low frequencies. Ina fancier setup, a multi-band graphic equalizer may allow you tovary a number of the frequency bands.

    Christopher F Baum Time-series filtering techniques in Stata 11

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    The effects of linear filtering

    Application of a linear filtereither FIR or IIRwill affect thecyclical components of a time series, and is often studied in thefrequency domain rather than the time domain. The filter is liableto alter the amplitude of any cyclical component. This effect variesaccording to the frequency of the component, and is described asthe gain of the filter.

    The concept is familiar to anyone who uses a stereo: the treblecontrol strengthens or weakens the high frequencies of yourfavorite tune, while the bass control affects the low frequencies. Ina fancier setup, a multi-band graphic equalizer may allow you tovary a number of the frequency bands.

    Christopher F Baum Time-series filtering techniques in Stata 12

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Christopher F Baum Time-series filtering techniques in Stata 13

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    In this example from iTunes equalizer, the low frequencies (32, 64,125 Hz) are toward the left, while the high frequencies (4 KHz, 8Khz, 16 Khz) are to the right. By moving the sliders up or down,we can cause the resulting filtered signal to contain only a subsetof the frequencies in the original music.

    This allows us to illustrate three kinds of time-series filters: thelowpass filter, which passes only the low (bass) frequencies; thehighpass filter, which passes only the high (treble) frequencies; andthe bandpass filter, which passes only the frequencies within acertain frequency band.

    For example:

    Christopher F Baum Time-series filtering techniques in Stata 14

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    In this example from iTunes equalizer, the low frequencies (32, 64,125 Hz) are toward the left, while the high frequencies (4 KHz, 8Khz, 16 Khz) are to the right. By moving the sliders up or down,we can cause the resulting filtered signal to contain only a subsetof the frequencies in the original music.

    This allows us to illustrate three kinds of time-series filters: thelowpass filter, which passes only the low (bass) frequencies; thehighpass filter, which passes only the high (treble) frequencies; andthe bandpass filter, which passes only the frequencies within acertain frequency band.

    For example:

    Christopher F Baum Time-series filtering techniques in Stata 15

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Christopher F Baum Time-series filtering techniques in Stata 16

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    This bandpass filter accentuates the components of the music inthe vicinity of 250 Hz - 500 Hz, and downplays all otherfrequencies. (Note that concert pitch, sounded by the oboe intuning a symphony orchestra, is A, 440 Hz). Since iTunesequalizer does not allow me to completely suppress the unwantedfrequencies, it is not a pure bandpass filter, but it does a prettygood jobin the sense that the resulting music sounds pretty bad!Those suppressed low and high frequencies are recognized asimportant components of the signal, or musical tones.

    Christopher F Baum Time-series filtering techniques in Stata 17

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    What does this have to do with economic time series? Thefrequencies in that case refer to the periodic behavior of the series.For instance, 2-5 year cycles in economic activity are often referredto as business cycle frequencies. Lower frequencies refer to longercycles in the data, while higher frequencies refer to, for instance,annual cycles in quarterly or monthly data: what we considerseasonality.

    The shortest period which we can study is a cycle lasting twoperiods, corresponding to the Nyquist frequency. If we wish tostudy shorter cyclese.g. quarterly movements in companies cashpositionswe must sample the data at a higher (monthly, weekly,daily) frequency.

    Christopher F Baum Time-series filtering techniques in Stata 18

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    What does this have to do with economic time series? Thefrequencies in that case refer to the periodic behavior of the series.For instance, 2-5 year cycles in economic activity are often referredto as business cycle frequencies. Lower frequencies refer to longercycles in the data, while higher frequencies refer to, for instance,annual cycles in quarterly or monthly data: what we considerseasonality.

    The shortest period which we can study is a cycle lasting twoperiods, corresponding to the Nyquist frequency. If we wish tostudy shorter cyclese.g. quarterly movements in companies cashpositionswe must sample the data at a higher (monthly, weekly,daily) frequency.

    Christopher F Baum Time-series filtering techniques in Stata 19

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Moving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Filtering economic time series

    The filtering techniques commonly applied to economic time series,usually sampled at quarterly, annual or monthly frequencies, maybe characterized as various sorts of lowpass, highpass or bandpassfilters. Unlike the application of moving averageswhere theaveraged series itself may be the object of interestthe filteringtechniques employed in economics often focus on producing asmoothed series xt and recovering the residual components of theoriginal series zt = xt xt as detrended xt .

    Christopher F Baum Time-series filtering techniques in Stata 20

    acerHighlight

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Stata filtering routines

    Taking advantage of the similarity between Statas Mata languageand that of MATLAB, I have produced translations of severalfiltering routines originally coded by Pawel Kowal of the WarsawSchool of Economics.

    These include:

    hprescott: HodrickPrescott filter

    bking: BaxterKing filter

    cfitzrw: Christiano-Fitzgerald random walk band pass filter

    butterworth: Butterworth square wave high pass filter

    Christopher F Baum Time-series filtering techniques in Stata 21

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Stata filtering routines

    Taking advantage of the similarity between Statas Mata languageand that of MATLAB, I have produced translations of severalfiltering routines originally coded by Pawel Kowal of the WarsawSchool of Economics.

    These include:

    hprescott: HodrickPrescott filter

    bking: BaxterKing filter

    cfitzrw: Christiano-Fitzgerald random walk band pass filter

    butterworth: Butterworth square wave high pass filter

    Christopher F Baum Time-series filtering techniques in Stata 22

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Stata filtering routines

    Taking advantage of the similarity between Statas Mata languageand that of MATLAB, I have produced translations of severalfiltering routines originally coded by Pawel Kowal of the WarsawSchool of Economics.

    These include:

    hprescott: HodrickPrescott filter

    bking: BaxterKing filter

    cfitzrw: Christiano-Fitzgerald random walk band pass filter

    butterworth: Butterworth square wave high pass filter

    Christopher F Baum Time-series filtering techniques in Stata 23

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Stata filtering routines

    Taking advantage of the similarity between Statas Mata languageand that of MATLAB, I have produced translations of severalfiltering routines originally coded by Pawel Kowal of the WarsawSchool of Economics.

    These include:

    hprescott: HodrickPrescott filter

    bking: BaxterKing filter

    cfitzrw: Christiano-Fitzgerald random walk band pass filter

    butterworth: Butterworth square wave high pass filter

    Christopher F Baum Time-series filtering techniques in Stata 24

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    HodrickPrescott filter

    For better or worse, the filter best known to most economics is theHP filter (J.Money,Credit,Banking 1997). As Ravn and Uhlig(Rev.Econ.Stat., 2002) state, ...the HP filter has become astandard method for removing trend movements in the businesscycle literature. As those authors state, use of the filter has beensubject to heavy criticism, but it has withstood the test of timeand the fire of discussion relatively well.

    One attraction of the HP filter is that it may be applied tononstationary time series (series containing one or more unit rootsin their autoregressive representation), a relevant concern for manymacroeconomic and financial time series.

    Christopher F Baum Time-series filtering techniques in Stata 25

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    HodrickPrescott filter

    For better or worse, the filter best known to most economics is theHP filter (J.Money,Credit,Banking 1997). As Ravn and Uhlig(Rev.Econ.Stat., 2002) state, ...the HP filter has become astandard method for removing trend movements in the businesscycle literature. As those authors state, use of the filter has beensubject to heavy criticism, but it has withstood the test of timeand the fire of discussion relatively well.

    One attraction of the HP filter is that it may be applied tononstationary time series (series containing one or more unit rootsin their autoregressive representation), a relevant concern for manymacroeconomic and financial time series.

    Christopher F Baum Time-series filtering techniques in Stata 26

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The HP filter removes a smooth trend t from a time series xt bysolving the minimization problem

    minT

    t=1

    [(xt t)2 + ((t+1 t) (t t1))2

    ]with respect to t . The residual, or deviation from trendzt = xt t is commonly referred to as the business cyclecomponent, and is the object of economic interest. In this sensethe HP filter is a highpass filter, removing the trend and returninghigh-frequency components in zt .

    The parameter penalizes fluctuations in the second differences ofxt , and must be specified by the user of the HP filter.

    Christopher F Baum Time-series filtering techniques in Stata 27

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Consider a time series xt = t + ct composed of trend and cyclicalcomponents (where the latter will also incorporate any irregularcomponents). If ct as well as the second difference of t isnormally and independently distributed, the HP filter is anoptimal filter and is given as the ratio of the two variances,2c

    22

    , where 2 is the second difference operator (Statas D2).

    With an unknown t , these variances are not known.

    Common wisdom has been to use = 1600 when applying the HPfilter to quarterly economic data. For other frequencies, Ravn andUhlig have shown that quite different values should be used: 6.25for annual data, and 129,600 for monthly data.

    Christopher F Baum Time-series filtering techniques in Stata 28

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Consider a time series xt = t + ct composed of trend and cyclicalcomponents (where the latter will also incorporate any irregularcomponents). If ct as well as the second difference of t isnormally and independently distributed, the HP filter is anoptimal filter and is given as the ratio of the two variances,2c

    22

    , where 2 is the second difference operator (Statas D2).

    With an unknown t , these variances are not known.

    Common wisdom has been to use = 1600 when applying the HPfilter to quarterly economic data. For other frequencies, Ravn andUhlig have shown that quite different values should be used: 6.25for annual data, and 129,600 for monthly data.

    Christopher F Baum Time-series filtering techniques in Stata 29

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The hprescott command

    The new hprescott command will apply the HP filter to one ormore variables in a time series context. It may be applied in apanel context with the by: prefix. The routine returns twovariables for each input variable: the smoothed series and thebusiness cycle component described as zt above. The syntax:

    hprescott varlist [if exp] [in range], stub(abbrev)[smooth(#)]

    where the stub provides prefixes for the new variables (and mustbe given). The smooth parameter gives , and defaults to 1600. IfStata can determine that the frequency of the data is annual ormonthly, the appropriate RavnUhlig value is used instead. In anycase the desired may be specified.

    Christopher F Baum Time-series filtering techniques in Stata 30

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The hprescott command

    This new hprescott command, written using Mata, is aconsiderable improvement of my previous version of the HP filter.That version, written in the ado-file language and translated fromPrescotts original Fortran code, ran quite slowly. It was not limitedby Statas matrix language limits as was Schmidts original routine(Stata Tech. Bull. 17), but even for series of moderate length theMata-based version runs about 4 times faster. The original routineis available for use by Stata 8.2 users as hprescott8, and isincluded in the SSC archive package hprescott.

    I will discuss the several filtering routines and then displayexamples of their application.

    Christopher F Baum Time-series filtering techniques in Stata 31

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    BaxterKing filter

    In contrast to the HP filtera highpass filterthe BaxterKingfilter (Rev.Econ.Stat., 1999) is a bandpass filter which allowssuppression of both the low frequency trend components and thehigh frequency components in an economic series. They argue thatthe National Bureau of Economic Research (NBER) definition of abusiness cycle requires a bandpass approach: for instance, retainingcomponents of the time series with periodic fluctuations betweensix and 32 quarters, while removing components at higher andlower frequencies.

    Christopher F Baum Time-series filtering techniques in Stata 32

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    In the theory of linear filtering, the optimal bandpass filter is welldefined, but it is a moving average of infinite order. Baxter andKings study focuses on constructing a good approximation to theoptimal filter. The approximation improves with a longer movingaverage, but a longer MA will drop additional observations at eachend of the filtered series. They conclude that three years of data(at either annual or quarterly frequencies) should be used toconstruct the filter.

    Christopher F Baum Time-series filtering techniques in Stata 33

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    BK set out six objectives for an appropriate filter: (1) it should notmodify the properties of the extracted component; (2) it shouldnot create phase shift, or alter the timing relationships in theseries; it should be an optimal approximation to the ideal bandpassfilter; (4) it should be applicable to I (1) or I (2) data, as well as toseries exhibiting a quadratic trend; (5) it should provide constant(non-time-varying) coefficients in the MA representation of thefilter; (6) it should be operational.

    The first two criteria imply that a moving average of the data withsymmetric weights on leads and lags must be defined. This in turnimplies that the filter will drop observations on both ends of theoriginal series.

    Christopher F Baum Time-series filtering techniques in Stata 34

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    BK set out six objectives for an appropriate filter: (1) it should notmodify the properties of the extracted component; (2) it shouldnot create phase shift, or alter the timing relationships in theseries; it should be an optimal approximation to the ideal bandpassfilter; (4) it should be applicable to I (1) or I (2) data, as well as toseries exhibiting a quadratic trend; (5) it should provide constant(non-time-varying) coefficients in the MA representation of thefilter; (6) it should be operational.

    The first two criteria imply that a moving average of the data withsymmetric weights on leads and lags must be defined. This in turnimplies that the filter will drop observations on both ends of theoriginal series.

    Christopher F Baum Time-series filtering techniques in Stata 35

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The bking command

    The new bking command will apply the BK filter to one or morevariables in a time series context. It may be applied in a panelcontext with the by: prefix. The routine returns a variablecontaining the filtered series. The syntax:

    bking varlist [if exp] [in range], plo(#) phi(#)stub(abbrev) [k(#)]

    where the stub provides prefixes for the new variables (and mustbe given). The plo and phi parameters give the minimumperiodicity and maximum periodicity to be included in the filteredseries. The optional parameter k gives the lead-lag length of thefilter. k observations will be lost at each end of the filtered series.

    Christopher F Baum Time-series filtering techniques in Stata 36

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The bking command

    For quarterly data, Baxter and King recommend theBurnsMitchell settings of 6 and 32 quarters (1.58 years) forplo, phi, and k=12. For annual data, they recommend 2 and 8years, with k=3, which implies a lowpass filter. For monthly data,they recommend 18 and 96 months (1.58 years), with k=12.

    This new bking command, written using Mata, is a considerableimprovement of my previous version of the BK filter. That version,written in the ado-file language using Statas matrix language(which restricted the length of series it could filter), ran quiteslowly relative to the Mata version. The original routine isavailable for use by Stata 8.2 users as bking8, and is included inthe SSC archive package bking.

    Christopher F Baum Time-series filtering techniques in Stata 37

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The bking command

    For quarterly data, Baxter and King recommend theBurnsMitchell settings of 6 and 32 quarters (1.58 years) forplo, phi, and k=12. For annual data, they recommend 2 and 8years, with k=3, which implies a lowpass filter. For monthly data,they recommend 18 and 96 months (1.58 years), with k=12.

    This new bking command, written using Mata, is a considerableimprovement of my previous version of the BK filter. That version,written in the ado-file language using Statas matrix language(which restricted the length of series it could filter), ran quiteslowly relative to the Mata version. The original routine isavailable for use by Stata 8.2 users as bking8, and is included inthe SSC archive package bking.

    Christopher F Baum Time-series filtering techniques in Stata 38

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    ChristianoFitzgerald random walk filter

    Christiano and Fitzgerald, in their Intl.Econ.Rev. (2003) article,discuss optimal finite-sample approximations to the ideal bandpassfilter, including one-sided filters that can be used in real time.Most of their work leads to quite complex structures that requirenumerical integration. Thankfully, they find that a simpleapproach, based on the generally false assumption that the dataare generated by a random walk, is nearly optimal.

    Christopher F Baum Time-series filtering techniques in Stata 39

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    CF conclude that optimal filter approximations violate some ofBKs desired properties: e.g., the weights in the OFA are notsymmetric in future and past values of the data, and they varyover time. They find that imposing stationary and symmetricweights on the approximation problem is usually inappropriate.

    They compare their random walk (RW) filter to the BK filter andan alternative based on regression on sine and cosine functions(the Trigonometric Regression filter) and find that the RW filterdominates in terms of an optimality criterion (match to theoptimal bandpass filter). Unlike the BK filter, no observations arelost by the RW filter.

    Christopher F Baum Time-series filtering techniques in Stata 40

    acerHighlight

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    CF also find that their RW filter is an improvement over the HPfilter when applied to quarterly data, particularly toward the end ofthe sample. The difference is small in most applications, but maybe more marked when the filters are applied to other datafrequencies.

    CF conclude that their RW filter compares very favorably to theoptimal approximation to the bandpass filter (i.e., one that doesnot involve the assumption of random walk behavior) for theeconomic series they study. Given that the RW filter is very easilycomputed, it provides an attractive alternative to HP, BK, and thecomputational burden of the optimal approximation.

    Christopher F Baum Time-series filtering techniques in Stata 41

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    CF also find that their RW filter is an improvement over the HPfilter when applied to quarterly data, particularly toward the end ofthe sample. The difference is small in most applications, but maybe more marked when the filters are applied to other datafrequencies.

    CF conclude that their RW filter compares very favorably to theoptimal approximation to the bandpass filter (i.e., one that doesnot involve the assumption of random walk behavior) for theeconomic series they study. Given that the RW filter is very easilycomputed, it provides an attractive alternative to HP, BK, and thecomputational burden of the optimal approximation.

    Christopher F Baum Time-series filtering techniques in Stata 42

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The cfitzrw command

    The cfitzrw command will apply the RW filter to one or morevariables in a time series context. It may be applied in a panelcontext with the by: prefix. The routine returns a variablecontaining the filtered series. The syntax:

    cfitzrw varlist [if exp] [in range], plo(#) phi(#)stub(abbrev)

    where the stub provides prefixes for the new variables (and mustbe given). The plo and phi parameters give the minimumperiodicity and maximum periodicity to be included in the filteredseries.

    The routine is available as the SSC package cfitzrw.

    Christopher F Baum Time-series filtering techniques in Stata 43

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Butterworth square-wave high pass filter

    In a recent artlcle in J. Econometrics (2000), Pollock argues thatcommonly used linear filters such as HP are not sufficiently flexiblein the context of common features of economic data: e.g. a sharpbreak in the underlying trend of a series. He advocates a rationalsquare-wave filter, known to engineers as the digital Butterworthfilter, as a better solution.

    Recall that the HP filter uses a single parameter, , to control thesmoothness of the trend series. Pollock points out that thisparameter affects both the location of the cut-off point on thefrequency axis and the rate of transition between the passband andstopband. In contrast, the Butterworth filter has greater flexibilityin approximating a phase-neutral square wave filter, which preciselydemarcates frequencies to be passed and frequencies to bediscarded.

    Christopher F Baum Time-series filtering techniques in Stata 44

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    Butterworth square-wave high pass filter

    In a recent artlcle in J. Econometrics (2000), Pollock argues thatcommonly used linear filters such as HP are not sufficiently flexiblein the context of common features of economic data: e.g. a sharpbreak in the underlying trend of a series. He advocates a rationalsquare-wave filter, known to engineers as the digital Butterworthfilter, as a better solution.

    Recall that the HP filter uses a single parameter, , to control thesmoothness of the trend series. Pollock points out that thisparameter affects both the location of the cut-off point on thefrequency axis and the rate of transition between the passband andstopband. In contrast, the Butterworth filter has greater flexibilityin approximating a phase-neutral square wave filter, which preciselydemarcates frequencies to be passed and frequencies to bediscarded.

    Christopher F Baum Time-series filtering techniques in Stata 45

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The Butterworth filter involves a smoothing operation which isapplied both forwards and backwards via a recursive filteringprocess to the time series to be filtered. The combination of theresulting filtered series is guaranteed to preserve phase, as thephase shifts caused by smoothing cancel each other.

    Such a recursive filter is sensitive to the initial conditions at eitherend of the time series. Pollock circumvents difficulties with initialconditions by generating them from a version of the data sequencewhich has been reduced to stationarity by repeated differencing.For the filter to work properly, the order of the filter must exceedthe number of unit roots in the series. The equivalent of the HPsmoothing parameter is determined by the user-specifiedminimum periodicity to be retained in the filtered series.

    Christopher F Baum Time-series filtering techniques in Stata 46

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    The Butterworth filter involves a smoothing operation which isapplied both forwards and backwards via a recursive filteringprocess to the time series to be filtered. The combination of theresulting filtered series is guaranteed to preserve phase, as thephase shifts caused by smoothing cancel each other.

    Such a recursive filter is sensitive to the initial conditions at eitherend of the time series. Pollock circumvents difficulties with initialconditions by generating them from a version of the data sequencewhich has been reduced to stationarity by repeated differencing.For the filter to work properly, the order of the filter must exceedthe number of unit roots in the series. The equivalent of the HPsmoothing parameter is determined by the user-specifiedminimum periodicity to be retained in the filtered series.

    Christopher F Baum Time-series filtering techniques in Stata 47

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    HodrickPrescott filterBaxterKing filterChristianoFitzgerald filterButterworth filter

    butterworth

    The butterworth command will apply the Butterworthsquare-wave high pass filter to one or more variables in a timeseries context. It may be applied in a panel context with the by:prefix. The routine returns a variable containing the filtered series.The syntax:

    butterworth varlist [if exp] [in range], freq(#)stub(abbrev) [order(#)]

    where the stub provides prefixes for the new variables (and mustbe given). The freq parameter gives the minimum period ofoscillation to be included in the filtered series. The optionalparameter order specifies the order of the filter (default 2).

    The routine is available as the SSC package butterworth.

    Christopher F Baum Time-series filtering techniques in Stata 48

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    8090

    100

    110

    120

    130

    US R

    eal E

    ffec

    tive

    Exch

    ange

    Rat

    e, m

    onth

    ly

    1980m1 1985m1 1990m1 1995m1 2000m1 2005m1date

    Christopher F Baum Time-series filtering techniques in Stata 49

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    8090

    100

    110

    120

    130

    1980m1 1985m1 1990m1 1995m1 2000m1 2005m1date

    US Real Effective Exchange Rate, monthly HP_usREER_sm_1

    Hodrick-Prescott estimated trend, lambda=129600

    Christopher F Baum Time-series filtering techniques in Stata 50

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    -10

    010

    20HP

    _usR

    EER_

    1

    1980m1 1985m1 1990m1 1995m1 2000m1 2005m1date

    HP-filtered US REER

    Christopher F Baum Time-series filtering techniques in Stata 51

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    -20

    24

    6BK

    _usR

    EER_

    1

    1980m1 1985m1 1990m1 1995m1 2000m1 2005m1date

    Baxter-King filtered US REER, plo=18, phi=96

    Christopher F Baum Time-series filtering techniques in Stata 52

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    -50

    510

    15CF

    _usR

    EER_

    1

    1980m1 1985m1 1990m1 1995m1 2000m1 2005m1date

    Christiano-Fitzgerald filtered US REER, plo=18, phi=96

    Christopher F Baum Time-series filtering techniques in Stata 53

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    -4-2

    02

    4BW

    _usR

    EER_

    1

    1980m1 1985m1 1990m1 1995m1 2000m1 2005m1date

    Butterworth filtered usREER, freq=18

    Christopher F Baum Time-series filtering techniques in Stata 54

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    -10

    010

    20

    1982m1 1984m1 1986m1 1988m1 1990m1date

    HP_usREER_1 BK_usREER_1CF_usREER_1 BW_usREER_1

    Alternate time series filters for US REER, 1982-1989

    Christopher F Baum Time-series filtering techniques in Stata 55

  • IntroductionTheory of time-series filtering

    Stata filtering routinesEmpirical illustrations

    Coming attractions and acknowledgements

    My research assistant and I are in the final stages of testing abandpass routine, based on Fitzgeralds MATLAB routine, thatimplements a number of alternative bandpass filters (including theTrigonometric Regression filter mentioned above). When thatroutine is available, it will be available from SSC as packagebandpass.

    I am grateful to Martha Lopez for the translation and testing ofseveral of these routines from MATLAB, and to the BostonCollege Undergraduate Research Assistant Program for funding herefforts on this project.

    Christopher F Baum Time-series filtering techniques in Stata 56

    IntroductionTheory of time-series filteringMoving average filtersSmoothersThe effects of linear filteringBandpass filters for economic time series

    Stata filtering routinesHodrick--Prescott filterBaxter--King filterChristiano--Fitzgerald filterButterworth filter

    Empirical illustrations