The tsfilter command separates a time series into trend and cyclical components. The trend component may contain a deterministic or a stochastic trend. The stationary cyclical component is driven by stochastic cycles at the specified periods.
Many time series contain trends and are thus nonstationary. Fitting nonstationary time series to statistical models can be difficult. Some researchers use filters to remove the trends and analyze the stationary components that the filters leave behind.
tsfilter implements the Baxter–King, Butterworth, Christiano–Fitzgerald, and Hodrick–Prescott filters commonly used for this purpose.
For example, we have quarterly data on GDP from 1952 through 2010.
. webuse gdp2 (Federal Reserve Economic Data, St. Louis Fed)
The data are strongly trended. Here is a graph of gdp_ln, the log of GDP over time, variable :
. tsline gdp_ln
We will use a Baxter–King band-pass filter for this series. Band-pass filters remove components below the minimum frequency or above the maximum frequency. Below we specify we want to remove frequencies with periods shorter than 6 months or longer than 32 months.
. tsfilter bk gdp_bk = gdp_ln, minperiod(6) maxperiod(32)
We have now created new variable gdp_bk containing the filtered series. To evaluate how the filter performed, we use Stata’s pergram command to compute and plot the periodogram of the filtered series. We put vertical lines at the minimum and maximum frequencies (1/32 and 1/6). If the filter did exactly want we want, the periodogram would be a horizontal line below the minimum and above the maximum frequencies.
. pergram gdp_bk, xline(0.03125 0.16667)
While the Baxter–King filter performed adequately, perhaps the Butterworth filter could do better. The Butterworth filter is a high-pass filter, meaning that it only removes the low-frequency components. High-pass filters can be used to make band-pass filters, but here we will just look at the high-pass results. The Butterworth filter has a tuning parameter called the order of the filter. We set the order of the filter to 8 in the application below.
. tsfilter bw gdp_bw = gdp_ln, order(8) maxperiod(32)
The resulting periodogram for this filtered series is
. pergram gdp_bw, xline(0.03125 0.16667)
The periodogram indicates that the Butterworth filter did a better job of removing the low-frequency components than the Baxter–King filter did.
We could continue with this story. We would filter the series using the Christiano–Fitzgerald band-pass filter and the Hodrick–Prescott high-pass filter and compare the results. The Christiano–Fitzgerald filter would produce results rivaling the Butterworth filter. The Hodrick–Prescott filter would not perform as well with these data.
Explore more time-series features in Stata.
Learn
Free webinars
NetCourses
Classroom and web training
Organizational training
Video tutorials
Third-party courses
Web resources
Teaching with Stata
© Copyright 1996–2024 StataCorp LLC. All rights reserved.
×
We use cookies to ensure that we give you the best experience on our website—to enhance site navigation, to analyze usage, and to assist in our marketing efforts. By continuing to use our site, you consent to the storing of cookies on your device and agree to delivery of content, including web fonts and JavaScript, from third party web services.
Cookie Settings
Last updated: 16 November 2022
StataCorp LLC (StataCorp) strives to provide our users with exceptional products and services. To do so, we must collect personal information from you. This information is necessary to conduct business with our existing and potential customers. We collect and use this information only where we may legally do so. This policy explains what personal information we collect, how we use it, and what rights you have to that information.
These cookies are essential for our website to function and do not store any personally identifiable information. These cookies cannot be disabled.
This website uses cookies to provide you with a better user experience. A cookie is a small piece of data our website stores on a site visitor's hard drive and accesses each time you visit so we can improve your access to our site, better understand how you use our site, and serve you content that may be of interest to you. For instance, we store a cookie when you log in to our shopping cart so that we can maintain your shopping cart should you not complete checkout. These cookies do not directly store your personal information, but they do support the ability to uniquely identify your internet browser and device.
Please note: Clearing your browser cookies at any time will undo preferences saved here. The option selected here will apply only to the device you are currently using.