Professional Documents
Culture Documents
July 2006
Christopher F Baum
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Introduction
There are several time-series filters commonly used in
macroeconomic and financial research to separate the behavior of a
timeseries into trend vs. cyclical and irregular components. These
techniques can usually be expressed in terms of linear algebra, and
reliable code exists in other matrix languages for their
implementation.
I briefly describe the concept of time-series filtering, and then
present several new implementations of time-series filters for Stata
users written in Mata. These routines avoid matrix size constraints
and are much faster than previous versions translated from Fortran
written in the ado-file language.
Christopher F Baum
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Introduction
There are several time-series filters commonly used in
macroeconomic and financial research to separate the behavior of a
timeseries into trend vs. cyclical and irregular components. These
techniques can usually be expressed in terms of linear algebra, and
reliable code exists in other matrix languages for their
implementation.
I briefly describe the concept of time-series filtering, and then
present several new implementations of time-series filters for Stata
users written in Mata. These routines avoid matrix size constraints
and are much faster than previous versions translated from Fortran
written in the ado-file language.
Christopher F Baum
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Theoretical background
The concepts of filtering in econometrics have been borrowed from
the engineering literature. Linear filtering involves generating a
linear combination of successive elements of a discrete-time signal
xt , as represented by
X
yt = (L)xt =
j xtj
j
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Smoothers
Official Stata contains a number of other routines to smooth and
forecast univariate time-series data, as described in [TS]
tssmooth. These include several recursive smoothers (exponential,
double exponential, and HoltWinters with and without seasonal
adjustments) 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 nonlinear
filter routines are generally used to extract the trend from a time
series while omitting the high-frequency or noise components. If
you are interested in those latter components, they may be
recovered as the difference between the original series and the
smoothed series.
Christopher F Baum
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Smoothers
Official Stata contains a number of other routines to smooth and
forecast univariate time-series data, as described in [TS]
tssmooth. These include several recursive smoothers (exponential,
double exponential, and HoltWinters with and without seasonal
adjustments) 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 nonlinear
filter routines are generally used to extract the trend from a time
series while omitting the high-frequency or noise components. If
you are interested in those latter components, they may be
recovered as the difference between the original series and the
smoothed series.
Christopher F Baum
10
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
11
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
12
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
13
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
In this example from iTunes equalizer, the low frequencies (32, 64,
125 Hz) are toward the left, while the high frequencies (4 KHz, 8
Khz, 16 Khz) are to the right. By moving the sliders up or down,
we can cause the resulting filtered signal to contain only a subset
of the frequencies in the original music.
This allows us to illustrate three kinds of time-series filters: the
lowpass filter, which passes only the low (bass) frequencies; the
highpass filter, which passes only the high (treble) frequencies; and
the bandpass filter, which passes only the frequencies within a
certain frequency band.
For example:
Christopher F Baum
14
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
In this example from iTunes equalizer, the low frequencies (32, 64,
125 Hz) are toward the left, while the high frequencies (4 KHz, 8
Khz, 16 Khz) are to the right. By moving the sliders up or down,
we can cause the resulting filtered signal to contain only a subset
of the frequencies in the original music.
This allows us to illustrate three kinds of time-series filters: the
lowpass filter, which passes only the low (bass) frequencies; the
highpass filter, which passes only the high (treble) frequencies; and
the bandpass filter, which passes only the frequencies within a
certain frequency band.
For example:
Christopher F Baum
15
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
16
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
17
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
18
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
19
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
20
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
21
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
22
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
23
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
24
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
HodrickPrescott filter
For better or worse, the filter best known to most economics is the
HP filter (J.Money,Credit,Banking 1997). As Ravn and Uhlig
(Rev.Econ.Stat., 2002) state, ...the HP filter has become a
standard method for removing trend movements in the business
cycle literature. As those authors state, use of the filter has been
subject to heavy criticism, but it has withstood the test of time
and the fire of discussion relatively well.
One attraction of the HP filter is that it may be applied to
nonstationary time series (series containing one or more unit roots
in their autoregressive representation), a relevant concern for many
macroeconomic and financial time series.
Christopher F Baum
25
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
HodrickPrescott filter
For better or worse, the filter best known to most economics is the
HP filter (J.Money,Credit,Banking 1997). As Ravn and Uhlig
(Rev.Econ.Stat., 2002) state, ...the HP filter has become a
standard method for removing trend movements in the business
cycle literature. As those authors state, use of the filter has been
subject to heavy criticism, but it has withstood the test of time
and the fire of discussion relatively well.
One attraction of the HP filter is that it may be applied to
nonstationary time series (series containing one or more unit roots
in their autoregressive representation), a relevant concern for many
macroeconomic and financial time series.
Christopher F Baum
26
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
T h
X
t=1
Christopher F Baum
27
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
28
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
29
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
30
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
31
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
BaxterKing filter
Christopher F Baum
32
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
33
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
BK set out six objectives for an appropriate filter: (1) it should not
modify the properties of the extracted component; (2) it should
not create phase shift, or alter the timing relationships in the
series; it should be an optimal approximation to the ideal bandpass
filter; (4) it should be applicable to I (1) or I (2) data, as well as to
series exhibiting a quadratic trend; (5) it should provide constant
(non-time-varying) coefficients in the MA representation of the
filter; (6) it should be operational.
The first two criteria imply that a moving average of the data with
symmetric weights on leads and lags must be defined. This in turn
implies that the filter will drop observations on both ends of the
original series.
Christopher F Baum
34
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
BK set out six objectives for an appropriate filter: (1) it should not
modify the properties of the extracted component; (2) it should
not create phase shift, or alter the timing relationships in the
series; it should be an optimal approximation to the ideal bandpass
filter; (4) it should be applicable to I (1) or I (2) data, as well as to
series exhibiting a quadratic trend; (5) it should provide constant
(non-time-varying) coefficients in the MA representation of the
filter; (6) it should be operational.
The first two criteria imply that a moving average of the data with
symmetric weights on leads and lags must be defined. This in turn
implies that the filter will drop observations on both ends of the
original series.
Christopher F Baum
35
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
36
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
37
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
38
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
39
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
40
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
41
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
42
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
43
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
44
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
45
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
46
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
Christopher F Baum
47
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
HodrickPrescott filter
BaxterKing filter
ChristianoFitzgerald filter
Butterworth filter
butterworth
The butterworth command will apply the Butterworth
square-wave high pass filter to one or more variables in a time
series 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 must
be given). The freq parameter gives the minimum period of
oscillation to be included in the filtered series. The optional
parameter order specifies the order of the filter (default 2).
The routine is available as the SSC package butterworth.
Christopher F Baum
48
80
130
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
1980m1
1985m1
1990m1
date
Christopher F Baum
1995m1
2000m1
2005m1
49
80
90
100
110
120
130
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
1980m1
1985m1
1990m1
date
1995m1
Christopher F Baum
2000m1
2005m1
HP_usREER_sm_1
50
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
-10
HP_usREER_1
0
10
20
HP-filtered US REER
1980m1
1985m1
1990m1
date
Christopher F Baum
1995m1
2000m1
2005m1
51
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
-2
BK_usREER_1
4
2
1980m1
1985m1
1990m1
date
Christopher F Baum
1995m1
2000m1
2005m1
52
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
-5
CF_usREER_1
5
10
15
1980m1
1985m1
1990m1
date
Christopher F Baum
1995m1
2000m1
2005m1
53
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
-4
-2
BW_usREER_1
0
1980m1
1985m1
1990m1
date
Christopher F Baum
1995m1
2000m1
2005m1
54
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
-10
10
20
1982m1
1984m1
1986m1
date
1988m1
HP_usREER_1
BK_usREER_1
CF_usREER_1
BW_usREER_1
Christopher F Baum
1990m1
55
Introduction
Theory of time-series filtering
Stata filtering routines
Empirical illustrations
Christopher F Baum
56