Title: | An Alternative to the Hodrick-Prescott Filter |
---|---|
Description: | In the working paper titled "Why You Should Never Use the Hodrick-Prescott Filter", James D. Hamilton proposes a new alternative to economic time series filtering. The neverhpfilter package provides functions and data for reproducing his work. Hamilton (2017) <doi:10.3386/w23429>. |
Authors: | Justin M. Shea [aut, cre] |
Maintainer: | Justin M. Shea <[email protected]> |
License: | GPL-3 |
Version: | 0.4-2 |
Built: | 2024-10-30 02:43:56 UTC |
Source: | https://github.com/justinmshea/neverhpfilter |
EXPGSC1
Real Exports of Goods and Services
data(EXPGSC1)
data(EXPGSC1)
An xts
object of Real Exports of Goods and Services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2012 Dollars
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-12-22 7:53 AM CST
BEA Account Code: A020RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/EXPGSC1.txt
data(EXPGSC1) tail(EXPGSC1) plot(EXPGSC1,grid.col = "white", col="blue")
data(EXPGSC1) tail(EXPGSC1) plot(EXPGSC1,grid.col = "white", col="blue")
FEDFUNDS
All Employees: Total Nonfarm
data(FEDFUNDS)
data(FEDFUNDS)
An xts
object of the Fed Funds figures.
Release: H.15 Selected Interest Rates
Seasonal Adjustment: Not Seasonally Adjusted
Frequency: Monthly
Units: Percent
Date Range: 1954-07-01 to 2021-11-01
Last Updated 2021-12-01 3:18 PM CST
Averages of daily figures.
The federal funds rate is the interest rate at which depository institutions trade federal funds (balances held at Federal Reserve Banks) with each other overnight. When a depository institution has surplus balances in its reserve account, it lends to other banks in need of larger balances. In simpler terms, a bank with excess cash, which is often referred to as liquidity, will lend to another bank that needs to quickly raise liquidity. (1) The rate that the borrowing institution pays to the lending institution is determined between the two banks; the weighted average rate for all of these types of negotiations is called the effective federal funds rate.(2) The effective federal funds rate is essentially determined by the market but is influenced by the Federal Reserve through open market operations to reach the federal funds rate target.(2) The Federal Open Market Committee (FOMC) meets eight times a year to determine the federal funds target rate. As previously stated, this rate influences the effective federal funds rate through open market operations or by buying and selling of government bonds (government debt). (2) More specifically, the Federal Reserve decreases liquidity by selling government bonds, thereby raising the federal funds rate because banks have less liquidity to trade with other banks. Similarly, the Federal Reserve can increase liquidity by buying government bonds, decreasing the federal funds rate because banks have excess liquidity for trade. Whether the Federal Reserve wants to buy or sell bonds depends on the state of the economy. If the FOMC believes the economy is growing too fast and inflation pressures are inconsistent with the dual mandate of the Federal Reserve, the Committee may set a higher federal funds rate target to temper economic activity. In the opposing scenario, the FOMC may set a lower federal funds rate target to spur greater economic activity. Therefore, the FOMC must observe the current state of the economy to determine the best course of monetary policy that will maximize economic growth while adhering to the dual mandate set forth by Congress. In making its monetary policy decisions, the FOMC considers a wealth of economic data, such as: trends in prices and wages, employment, consumer spending and income, business investments, and foreign exchange markets.
The federal funds rate is the central interest rate in the U.S. financial market. It influences other interest rates such as the prime rate, which is the rate banks charge their customers with higher credit ratings. Additionally, the federal funds rate indirectly influences longer- term interest rates such as mortgages, loans, and savings, all of which are very important to consumer wealth and confidence.(2)
References (1) Federal Reserve Bank of New York. “Federal funds.” Fedpoints, August 2007. (2) Board of Governors of the Federal Reserve System. “Monetary Policy”. http://www.federalreserve.gov/monetarypolicy/default.htm.
Board of Governors of the Federal Reserve System (US) https://fred.stlouisfed.org/data/FEDFUNDS.txt
data(FEDFUNDS) tail(FEDFUNDS) plot(FEDFUNDS, grid.col = "white", col="green")
data(FEDFUNDS) tail(FEDFUNDS) plot(FEDFUNDS, grid.col = "white", col="green")
GCEC1
Real Government Consumption Expenditures and Gross Investment
data(GCEC1)
data(GCEC1)
An xts
object containing observations of Real Exports of Goods and Services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2012 Dollars
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-12-22 7:53 AM CST
BEA Account Code: A822RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GCEC1.txt
data(GCEC1) tail(GCEC1) plot(GCEC1, grid.col = "white", col="blue")
data(GCEC1) tail(GCEC1) plot(GCEC1, grid.col = "white", col="blue")
GDPC1
Real Gross Domestic Product
data(GDPC1)
data(GDPC1)
An xts
object of Real Gross Domestic Product.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2012 Dollars
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-12-22 7:53 AM CST
Real gross domestic product is the inflation adjusted value of the goods and services produced by labor and property located in the United States.
For more information see the Guide to the National Income and Product Accounts of the United States (NIPA) - https://www.bea.gov/resources/methodologies/nipa-handbook.
BEA Account Code: A191RX
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GDPC1.txt
data(GDPC1) log_RGDP <- 100*log(GDPC1) gdp_cycle <- yth_filter(log_RGDP, h = 8, p = 4, output = c("cycle", "random"), family = gaussian) main <- "Log of Real GDP cycle and random walk" plot(gdp_cycle, grid.col = "white", legend.loc = "topright", main = main)
data(GDPC1) log_RGDP <- 100*log(GDPC1) gdp_cycle <- yth_filter(log_RGDP, h = 8, p = 4, output = c("cycle", "random"), family = gaussian) main <- "Log of Real GDP cycle and random walk" plot(gdp_cycle, grid.col = "white", legend.loc = "topright", main = main)
GDPDEF
Gross Domestic Product: Implicit Price Deflator
data(GDPDEF)
data(GDPDEF)
An xts
object containing observations of Real Exports of Goods and Services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Index 2012 = 100
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-11-24 7:55 AM CST
BEA Account Code: A191RD
The number of decimal places reported varies over time. A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GDPDEF.txt
data(GDPDEF) head(GDPDEF) tail(GDPDEF) plot(GDPDEF, col = "blue")
data(GDPDEF) head(GDPDEF) tail(GDPDEF) plot(GDPDEF, col = "blue")
GPDIC1
Real Gross Private Domestic Investment
data(GPDIC1)
data(GPDIC1)
An xts
object of Real Exports of Goods and Services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2012 Dollars
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-12-22 7:53 AM CST
BEA Account Code: A006RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GPDIC1.txt
data(GPDIC1) tail(GPDIC1) plot(GPDIC1, grid.col = "white", col="blue")
data(GPDIC1) tail(GPDIC1) plot(GPDIC1, grid.col = "white", col="blue")
GS10
10-Year Treasury Constant Maturity Rate
data(GS10)
data(GS10)
An xts
object containing observations of the 10-Year Treasury Constant Maturity Rate.
Release: H.15 Selected Interest Rates
Seasonal Adjustment: Not Seasonally Adjusted
Frequency: Monthly
Units: Percent
Date Range: 1953-04-01 to 2021-11-01
Last Updated 2021-12-01 3:18 PM CST
Averages of business days.
For further information regarding treasury constant maturity data, please refer to http://www.federalreserve.gov/releases/h15/current/h15.pdf and http://www.treasury.gov/resource-center/data-chart-center/interest-rates/Pages/yieldmethod.aspx.
Board of Governors of the Federal Reserve System (US) https://fred.stlouisfed.org/data/GS10.txt
data(GS10) tail(GS10) plot(GS10, grid.col = "white", col="green")
data(GS10) tail(GS10) plot(GS10, grid.col = "white", col="green")
Standard deviation of cyclical component and correlation with cyclical component of GDP for assorted macroeconomic series.
data("Hamilton_table_2")
data("Hamilton_table_2")
A data.frame containing 13 economic time series observations of 5 variables.
cycle.sd Standard deviation of the cycle component, computed with function 'yth_filter(x, output = "cycle")'
gdp.cor Correlation of 'cycle.sd' with the cycle.sd of 100 * log(RealGDP)
random.sd Standard deviation of a Random-walk, computed by a rolling differencing the series by period 'h', the same passed to 'yth_filter(x, output = "cycle")' to compute 'cycle.sd'.
gdp.rand.cor Correlation of 'random.sd' with the random.sd of 100 * log(RealGDP).
Filtered series were based on the full sample available for that variable, while correlations were calculated using the subsample of overlapping values for the two indicators. Note that the regression residuals lose the first 11 observations and the random-walk calculations lose the first 8 observations.
"Why You Should Never Use the Hodrick-Prescott Filter", pg. 40 http://econweb.ucsd.edu/~jhamilto/hp.pdf
print(Hamilton_table_2)
print(Hamilton_table_2)
IMPGSC1
Real imports of goods and services
data(IMPGSC1)
data(IMPGSC1)
An xts
object of Real imports of goods and services.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2012 Dollars
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-12-22 7:53 AM CST
BEA Account Code: A021RX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/IMPGSC1.txt
data(IMPGSC1) tail(IMPGSC1) plot(IMPGSC1,grid.col = "white", col="blue")
data(IMPGSC1) tail(IMPGSC1) plot(IMPGSC1,grid.col = "white", col="blue")
PAYEMS
All Employees: Total Nonfarm
data(PAYEMS)
data(PAYEMS)
An xts
object containing observations of All Employees: Total Nonfarm.
Release: Employment Situation
Seasonal Adjustment: Seasonally Adjusted
Frequency: Monthly
Units: Thousands of Persons
Date Range: 1939-01-01 to 2021-11-01
Last Updated 2021-12-03 9:10 AM CST
All Employees: Total Nonfarm, commonly known as Total Nonfarm Payroll, is a measure of the number of U.S. workers in the economy that excludes proprietors, private household employees, unpaid volunteers, farm employees, and the unincorporated self-employed. This measure accounts for approximately 80 percent of the workers who contribute to Gross Domestic Product (GDP).
This measure provides useful insights into the current economic situation because it can represent the number of jobs added or lost in an economy. Increases in employment might indicate that businesses are hiring which might also suggest that businesses are growing. Additionally, those who are newly employed have increased their personal incomes, which means (all else constant) their disposable incomes have also increased, thus fostering further economic expansion.
Generally, the U.S. labor force and levels of employment and unemployment are subject to fluctuations due to seasonal changes in weather, major holidays, and the opening and closing of schools. The Bureau of Labor Statistics (BLS) adjusts the data to offset the seasonal effects to show non-seasonal changes: for example, women's participation in the labor force; or a general decline in the number of employees, a possible indication of a downturn in the economy. To closely examine seasonal and non-seasonal changes, the BLS releases two monthly statistical measures: the seasonally adjusted All Employees: Total Nonfarm (FEDFUNDS) and All Employees: Total Nonfarm (PAYNSA), which is not seasonally adjusted.
The series comes from the 'Current Employment Statistics (Establishment Survey).
The source code is: CES0000000001
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/PAYEMS.txt
data(PAYEMS) tail(PAYEMS) PAYEMS_qtr <- xts::to.quarterly(PAYEMS["1947/"], OHLC = FALSE) log_Employment <- 100*log(PAYEMS_qtr) employ_trend <- yth_filter(log_Employment, h = 8, p = 4, output = c("x", "trend"), family = gaussian) main <- "Log of Employment and trend" plot(employ_trend, grid.col = "white", legend.loc = "topleft", main = main) employ_cycle <- yth_filter(log_Employment, h = 8, p = 4, output = c("cycle", "random"), family = gaussian) main <- "Log of Employment cycle and random walk" plot(employ_cycle, grid.col = "white", legend.loc = "topright", main = main)
data(PAYEMS) tail(PAYEMS) PAYEMS_qtr <- xts::to.quarterly(PAYEMS["1947/"], OHLC = FALSE) log_Employment <- 100*log(PAYEMS_qtr) employ_trend <- yth_filter(log_Employment, h = 8, p = 4, output = c("x", "trend"), family = gaussian) main <- "Log of Employment and trend" plot(employ_trend, grid.col = "white", legend.loc = "topleft", main = main) employ_cycle <- yth_filter(log_Employment, h = 8, p = 4, output = c("cycle", "random"), family = gaussian) main <- "Log of Employment cycle and random walk" plot(employ_cycle, grid.col = "white", legend.loc = "topright", main = main)
PCECC96
Real Personal Consumption Expenditures
data(PCECC96)
data(PCECC96)
An xts
object of Real Personal Consumption Expenditures.
Release: Gross Domestic Product
Seasonal Adjustment: Seasonally Adjusted Annual Rate
Frequency: Quarterly
Units: Billions of Chained 2012 Dollars
Date Range: 1947-01-01 to 2021-07-01
Last Updated 2021-12-22 7:52 AM CST
BEA Account Code: DPCERX
A Guide to the National Income and Product Accounts of the United States (NIPA) - (http://www.bea.gov/national/pdf/nipaguid.pdf)
U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/PCECC96.txt
data(PCECC96) tail(PCECC96) plot(PCECC96,grid.col = "white", col="blue")
data(PCECC96) tail(PCECC96) plot(PCECC96,grid.col = "white", col="blue")
SP500
Robert Schiller's data set for U.S. Stock Markets 1871-2021 and CAPE Ratio.
data(SP500)
data(SP500)
An xts
object containing observations of U.S. Stock Markets 1871-Present and CAPE Ratio.
Frequency: Monthly
Date Range: 1871-01 to 2020-03
Data updated: 2021-05-05 05:08 PM CST
SP500: Nominal prices of the S&P composite index, April 2021 observation is 04/05 close
Dividends: Nominal dividends
Earnings: Nominal Earnings, S&P 500 estimated
CPI: Schiller's Consumer Price Index data Schiller used for transformation to Real prices
GS10: Schiller's Long term interest rate 10-Year Treasury Constant Maturity Rate, April 2021 observation is 04/05 close
Real_SP500: Real prices of the S&P 500 composite index
Real_Dividends: Real Dividends
Real_SP500_TR: Real Total Return Price of the S&P 500 composite index
Real_Earnings: Real Earnings
Real_Earnings_TR: Real Total Return Scaled Earnings
CAPE: Cyclically Adjusted Price Earnings Ratio. P/E10 or CAPE.
CAPE_TR: Cyclically Adjusted Total Return Price Earnings Ratio. P/E10_TR or CAPE_TR.
CAPE_Yield: Excess Cape Yield.
Bond_TR: Total Bond Returns.
Real_Bond_TR: Real Total Bond Returns.
This data set consists of monthly stock price, dividends, and earnings data and the consumer price index (to allow conversion to real values), all starting January 1871. The price, dividend, and earnings series are from the same sources as described in Chapter 26 of my earlier book (Market Volatility, Cambridge, MA: MIT Press, 1989), although now I use monthly data, rather than annual data. Monthly dividend and earnings data are computed from the S&P four-quarter totals for the quarter since 1926, with linear interpolation to monthly figures. Dividend and earnings data before 1926 are from Cowles and associates (Common Stock Indexes, 2nd ed., Bloomington, Ind.: Principia Press, 1939), interpolated from annual data. Stock price data are monthly averages of daily closing prices. The CPI-U (Consumer Price Index-All Urban Consumers) published by the U.S. Bureau of Labor Statistics begins in 1913; for years before 1913, I spliced to the CPI Warren and Pearson's price index, by multiplying it by the ratio of the indexes in January 1913. December 1999 and January 2000 values for the CPI-Uare extrapolated. See George F. Warren and Frank A. Pearson, Gold and Prices (New York: John Wiley and Sons, 1935). Data are from their Table 1, pp. 11–14.
Schiller, Robert J. Irrational Exuberance, Princeton University Press 2000, Broadway Books 2001, 2nd ed. 2005, 3rd ed. 2015. http://www.econ.yale.edu/~shiller/data.htm
Download .xls file directly from here: http://www.econ.yale.edu/~shiller/data/ie_data.xls
data(SP500) SP500_qtr <- xts::to.quarterly(SP500$SP500, OHLC = FALSE) log_SP500 <- 100*log(SP500_qtr) SP500_trend <- yth_filter(log_SP500, h = 8, p = 4, output = c("x", "trend"), family = gaussian) main <- "Log of SP500 and trend" plot(SP500_trend, grid.col = "white", legend.loc = "topleft", main = main) SP500cycle <- yth_filter(log_SP500["1900/"], h = 8, p = 4, output = c("cycle", "random"), family = gaussian) main <- "Log of SP500 cycle and random walk" plot(SP500cycle, grid.col = "white", legend.loc = "topright", main = main)
data(SP500) SP500_qtr <- xts::to.quarterly(SP500$SP500, OHLC = FALSE) log_SP500 <- 100*log(SP500_qtr) SP500_trend <- yth_filter(log_SP500, h = 8, p = 4, output = c("x", "trend"), family = gaussian) main <- "Log of SP500 and trend" plot(SP500_trend, grid.col = "white", legend.loc = "topleft", main = main) SP500cycle <- yth_filter(log_SP500["1900/"], h = 8, p = 4, output = c("cycle", "random"), family = gaussian) main <- "Log of SP500 cycle and random walk" plot(SP500cycle, grid.col = "white", legend.loc = "topright", main = main)
UNRATENSA
Civilian Unemployment Rate
data(UNRATENSA)
data(UNRATENSA)
An xts
object of the Civilian Unemployment Rate.
Release: Employment Situation
Seasonal Adjustment: Not Seasonally Adjusted
Frequency: Monthly
Units: Percent
Date Range: 1948-01-01 to 2021-11-01
Last Updated 2021-12-03 9:35 AM CST
The unemployment rate represents the number of unemployed as a percentage of the labor force. Labor force data are restricted to people 16 years of age and older, who currently reside in 1 of the 50 states or the District of Columbia, who do not reside in institutions (e.g., penal and mental facilities, homes for the aged), and who are not on active duty in the Armed Forces.
This rate is also defined as the U-3 measure of labor underutilization.
The series comes from the 'Current Population Survey (Household Survey)'
The source code is: LNU04000000
U.S. Bureau of Labor Statistics https://fred.stlouisfed.org/data/UNRATENSA.txt
data(UNRATENSA) tail(UNRATENSA) plot(UNRATENSA, grid.col = "white", col="green")
data(UNRATENSA) tail(UNRATENSA) plot(UNRATENSA, grid.col = "white", col="green")
USREC
NBER based Recession Indicators for the United States from the
Period following the Peak through the Trough
data(USREC)
data(USREC)
An xts
object containing monthly observations of NBER
based Recession Indicators
#
Release: Recession Indicators Series (Not a Press Release)
Seasonal Adjustment: Not Seasonally Adjusted
Frequency: Monthly
Units: +1 or 0
Date Range: 1854-12-01 to 2021-11-01
Last Updated 2021-12-01 6:01 PM CST
This time series is an interpretation of US Business Cycle Expansions and Contractions data provided by The National Bureau of Economic Research (NBER) at http://www.nber.org/cycles/cyclesmain.html. Our time series is composed of dummy variables that represent periods of expansion and recession. The NBER identifies months and quarters of turning points without designating a date within the period that turning points occurred. The dummy variable adopts an arbitrary convention that the turning point occurred at a specific date within the period. The arbitrary convention does not reflect any judgment on this issue by the NBER's Business Cycle Dating Committee. A value of 1 is a recessionary period, while a value of 0 is an expansionary period. For this time series, the recession begins the first day of the period following a peak and ends on the last day of the period of the trough. For more options on recession shading, see the notes and links below.
The recession shading data that we provide initially comes from the source as a list of dates that are either an economic peak or trough. We interpret dates into recession shading data using one of three arbitrary methods. All of our recession shading data is available using all three interpretations. The period between a peak and trough is always shaded as a recession. The peak and trough are collectively extrema. Depending on the application, the extrema, both individually and collectively, may be included in the recession period in whole or in part. In situations where a portion of a period is included in the recession, the whole period is deemed to be included in the recession period.
The first interpretation, known as the midpoint method, is to show a recession from the midpoint of the peak through the midpoint of the trough for monthly and quarterly data. For daily data, the recession begins on the 15th of the month of the peak and ends on the 15th of the month of the trough. Daily data is a disaggregation of monthly data. For monthly and quarterly data, the entire peak and trough periods are included in the recession shading. This method shows the maximum number of periods as a recession for monthly and quarterly data. The Federal Reserve Bank of St. Louis uses this method in its own publications. A version of this time series represented using the midpoint method can be found at: https://fred.stlouisfed.org/series/USRECM
The second interpretation, known as the trough method, is to show a recession from the period following the peak through the trough (i.e. the peak is not included in the recession shading, but the trough is). For daily data, the recession begins on the first day of the first month following the peak and ends on the last day of the month of the trough. Daily data is a disaggregation of monthly data. The trough method is used when displaying data on FRED graphs. The trough method is used for this series.
The third interpretation, known as the peak method, is to show a recession from the period of the peak to the trough (i.e. the peak is included in the recession shading, but the trough is not). For daily data, the recession begins on the first day of the month of the peak and ends on the last day of the month preceding the trough. Daily data is a disaggregation of monthly data. A version of this time series represented using the peak method can be found at: https://fred.stlouisfed.org/series/USRECP
Federal Reserve Bank of St. Louis https://fred.stlouisfed.org/data/USREC.txt
data(USREC) USREC["2007/2009"] plot(USREC["1947/"], grid.col = "white", col="red")
data(USREC) USREC["2007/2009"] plot(USREC["1947/"], grid.col = "white", col="red")
yth_filter
returns an xts
object containing user defined
combinations of the original, trend, cycle, and random walk series.
yth_filter(x, h = 8, p = 4, output = c("x", "trend", "cycle", "random"), ...)
yth_filter(x, h = 8, p = 4, output = c("x", "trend", "cycle", "random"), ...)
x |
A univariate |
h |
An |
p |
An |
output |
A |
... |
other arguments passed to the function |
For time series of quarterly periodicity, Hamilton suggests parameters of
h = 8 and p = 4, or an process, additionally lagged by
lookahead periods. Econometricians may explore variations of h. However, p
is designed to correspond with the seasonality of a given periodicity and
should be matched accordingly.
Which can be rewritten as:
An xts
object defined by the output
parameter.
James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.
data(GDPC1) gdp_filter <- yth_filter(100*log(GDPC1), h = 8, p = 4) head(gdp_filter, 15) #---------------------------------------------------------------------------# data(PAYEMS) log_Employment <- 100*log(xts::to.quarterly(PAYEMS["1947/2016-6"], OHLC = FALSE)) employ_trend <- yth_filter(log_Employment, h = 8, p = 4, output = c("x", "trend")) plot(employ_trend, grid.col = "white", legend.loc = "topleft", main = "Log of Employment and trend") #----------------------------------------------------------------------------# quarterly_data <- 100*log(merge(GDPC1, PCECC96, GPDIC1, EXPGSC1, IMPGSC1, GCEC1, GDPDEF)) cycle <- do.call(merge, lapply(quarterly_data, yth_filter, output = "cycle")) random <- do.call(merge, lapply(quarterly_data, yth_filter, output = "random")) cycle.sd <- t(data.frame(lapply(cycle, sd, na.rm = TRUE))) GDP.cor <- t(data.frame(lapply(cycle, cor, cycle[,1], use = "complete.obs"))) random.sd <- t(data.frame(lapply(random, sd, na.rm = TRUE))) random.cor <- t(data.frame(lapply(random, cor, random[,1], use = "complete.obs"))) my_table_2 <- round(data.frame(cbind(cycle.sd, GDP.cor, random.sd, random.cor)), 2) names(my_table_2) <- names(Hamilton_table_2)[1:4] my_table_2
data(GDPC1) gdp_filter <- yth_filter(100*log(GDPC1), h = 8, p = 4) head(gdp_filter, 15) #---------------------------------------------------------------------------# data(PAYEMS) log_Employment <- 100*log(xts::to.quarterly(PAYEMS["1947/2016-6"], OHLC = FALSE)) employ_trend <- yth_filter(log_Employment, h = 8, p = 4, output = c("x", "trend")) plot(employ_trend, grid.col = "white", legend.loc = "topleft", main = "Log of Employment and trend") #----------------------------------------------------------------------------# quarterly_data <- 100*log(merge(GDPC1, PCECC96, GPDIC1, EXPGSC1, IMPGSC1, GCEC1, GDPDEF)) cycle <- do.call(merge, lapply(quarterly_data, yth_filter, output = "cycle")) random <- do.call(merge, lapply(quarterly_data, yth_filter, output = "random")) cycle.sd <- t(data.frame(lapply(cycle, sd, na.rm = TRUE))) GDP.cor <- t(data.frame(lapply(cycle, cor, cycle[,1], use = "complete.obs"))) random.sd <- t(data.frame(lapply(random, sd, na.rm = TRUE))) random.cor <- t(data.frame(lapply(random, cor, random[,1], use = "complete.obs"))) my_table_2 <- round(data.frame(cbind(cycle.sd, GDP.cor, random.sd, random.cor)), 2) names(my_table_2) <- names(Hamilton_table_2)[1:4] my_table_2
yth_glm
fits a generalized linear model suggested by James D. Hamilton as a better alternative to the Hodrick-Prescott Filter.
yth_glm(x, h = 8, p = 4, ...)
yth_glm(x, h = 8, p = 4, ...)
x |
A univariate |
h |
An |
p |
An |
... |
all arguments passed to the function |
For time series of quarterly periodicity, Hamilton suggests parameters of
h = 8 and p = 4, or an process, additionally lagged by
lookahead periods. Econometricians may explore variations of h. However, p is designed to correspond with the seasonality of a given periodicity and should be matched accordingly.
Which can be rewritten as:
yth_glm
returns a generalized linear model object of class glm
,
which inherits from lm
.
James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.
data(GDPC1) gdp_model <- yth_glm(GDPC1, h = 8, p = 4, family = gaussian) summary(gdp_model) plot(gdp_model)
data(GDPC1) gdp_model <- yth_glm(GDPC1, h = 8, p = 4, family = gaussian) summary(gdp_model) plot(gdp_model)