Package 'neverhpfilter'

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

Help Index


Real Exports of Goods and Services

Description

EXPGSC1 Real Exports of Goods and Services

Usage

data(EXPGSC1)

Format

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

Notes

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)

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/EXPGSC1.txt

Examples

data(EXPGSC1)
tail(EXPGSC1)
plot(EXPGSC1,grid.col = "white", col="blue")

Effective Federal Funds Rate

Description

FEDFUNDS All Employees: Total Nonfarm

Usage

data(FEDFUNDS)

Format

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

Notes

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.

Source

Board of Governors of the Federal Reserve System (US) https://fred.stlouisfed.org/data/FEDFUNDS.txt

Examples

data(FEDFUNDS)
tail(FEDFUNDS)
plot(FEDFUNDS, grid.col = "white", col="green")

Real Government Consumption Expenditures and Gross Investment

Description

GCEC1 Real Government Consumption Expenditures and Gross Investment

Usage

data(GCEC1)

Format

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

Notes

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)

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GCEC1.txt

Examples

data(GCEC1)
tail(GCEC1)
plot(GCEC1, grid.col = "white", col="blue")

Gross Domestic Product

Description

GDPC1 Real Gross Domestic Product

Usage

data(GDPC1)

Format

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

Notes

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

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GDPC1.txt

Examples

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)

Gross Domestic Product: Implicit Price Deflator

Description

GDPDEF Gross Domestic Product: Implicit Price Deflator

Usage

data(GDPDEF)

Format

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

Notes

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)

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GDPDEF.txt

Examples

data(GDPDEF)
head(GDPDEF)
tail(GDPDEF)
plot(GDPDEF, col = "blue")

Real Gross Private Domestic Investment

Description

GPDIC1 Real Gross Private Domestic Investment

Usage

data(GPDIC1)

Format

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

Notes

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)

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/GPDIC1.txt

Examples

data(GPDIC1)

tail(GPDIC1)

plot(GPDIC1, grid.col = "white", col="blue")

10-Year Treasury Constant Maturity Rate

Description

GS10 10-Year Treasury Constant Maturity Rate

Usage

data(GS10)

Format

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

Notes

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.

Source

Board of Governors of the Federal Reserve System (US) https://fred.stlouisfed.org/data/GS10.txt

Examples

data(GS10)
tail(GS10)
plot(GS10, grid.col = "white", col="green")

Hamilton_table_2

Description

Standard deviation of cyclical component and correlation with cyclical component of GDP for assorted macroeconomic series.

Usage

data("Hamilton_table_2")

Format

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).

Notes

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.

Source

"Why You Should Never Use the Hodrick-Prescott Filter", pg. 40 http://econweb.ucsd.edu/~jhamilto/hp.pdf

Examples

print(Hamilton_table_2)

Real imports of goods and services

Description

IMPGSC1 Real imports of goods and services

Usage

data(IMPGSC1)

Format

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

Notes

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)

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/IMPGSC1.txt

Examples

data(IMPGSC1)
tail(IMPGSC1)
plot(IMPGSC1,grid.col = "white", col="blue")

Employment Situation

Description

PAYEMS All Employees: Total Nonfarm

Usage

data(PAYEMS)

Format

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

Notes

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

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/PAYEMS.txt

Examples

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)

Real Personal Consumption Expenditures

Description

PCECC96 Real Personal Consumption Expenditures

Usage

data(PCECC96)

Format

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

Notes

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)

Source

U.S. Bureau of Economic Analysis https://fred.stlouisfed.org/data/PCECC96.txt

Examples

data(PCECC96)
tail(PCECC96)
plot(PCECC96,grid.col = "white", col="blue")

U.S. Stock Markets and CAPE Ratio

Description

SP500 Robert Schiller's data set for U.S. Stock Markets 1871-2021 and CAPE Ratio.

Usage

data(SP500)

Format

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.

Notes from Schiller

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.

Source

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

Examples

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)

Civilian Unemployment Rate

Description

UNRATENSA Civilian Unemployment Rate

Usage

data(UNRATENSA)

Format

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

Notes

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

Source

U.S. Bureau of Labor Statistics https://fred.stlouisfed.org/data/UNRATENSA.txt

Examples

data(UNRATENSA)
tail(UNRATENSA)
plot(UNRATENSA, grid.col = "white", col="green")

Recession Indicators Series

Description

USREC NBER based Recession Indicators for the United States from the Period following the Peak through the Trough

Usage

data(USREC)

Format

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

Notes

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

Source

Federal Reserve Bank of St. Louis https://fred.stlouisfed.org/data/USREC.txt

Examples

data(USREC)
USREC["2007/2009"]
plot(USREC["1947/"], grid.col = "white", col="red")

Filtered xts object

Description

yth_filter returns an xts object containing user defined combinations of the original, trend, cycle, and random walk series.

Usage

yth_filter(x, h = 8, p = 4, output = c("x", "trend", "cycle", "random"), ...)

Arguments

x

A univariate xts object of any zoo index class, such as Date, yearmon, or yearqtr. For converting objects of type timeSeries, ts, irts, fts, matrix, data.frame or zoo, please read as.xts.

h

An integer, defining the lookahead period. Defaults to h = 8. The default assumes economic data of quarterly periodicity with a lookahead period of 2 years. This function is not limited by the default parameter, and Econometricians may change it as required.

p

An integer, indicating the number of lags. A Default of p = 4, assumes data is of quarterly periodicity. If data is of monthly periodicity, one may choose p = 12 or aggregate the series to quarterly periodicity and maintain the default. Econometricians should use this parameter to accommodate the Seasonality of their data.

output

A character vector. Defaults to output = c("x","trend", "cycle", "random"), which returns the original time series (x), yth_glm fitted.values ("trend"), yth_glm residuals ("cycle"), and a random walk series defined by differencing yt+hy_{t+h} and yty_t ("random"). Arguments "x", "trend", "cycle", and "random" extract their corresponding univariate series and can be merged in any combination. For example c("x", "trend") returns both the original series "x" and the "trend" components. c("cycle", "random") will return both the "cycle" and "random" components.

...

other arguments passed to the function glm

Details

For time series of quarterly periodicity, Hamilton suggests parameters of h = 8 and p = 4, or an AR(4)AR(4) process, additionally lagged by 88 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.

yt+h=β0+β1yt+β2yt1+β3yt2+β4yt3+vt+hy_{t+h} = \beta_0 + \beta_1 y_t + \beta_2 y_{t-1} + \beta_3 y_{t-2} + \beta_4 y_{t-3} + v_{t+h}

v^t+h=yt+hβ^0+β^1yt+β^2yt1+β^3yt2+β^4yt3\hat{v}_{t+h} = y_{t+h} - \hat{\beta}_0 + \hat{\beta}_1 y_t + \hat{\beta}_2 y_{t-1} + \hat{\beta}_3 y_{t-2} + \hat{\beta}_4 y_{t-3}

Which can be rewritten as:

yt=β0+β1yt8+β2yt9+β3yt10+β4yt11+vty_{t} = \beta_0 + \beta_1 y_{t-8} + \beta_2 y_{t-9} + \beta_3 y_{t-10} + \beta_4 y_{t-11} + v_{t}

v^t=ytβ^0+β^1yt8+β^2yt9+β^3yt10+β^4yt11\hat{v}_{t} = y_{t} - \hat{\beta}_0 + \hat{\beta}_1 y_{t-8} + \hat{\beta}_2 y_{t-9} + \hat{\beta}_3 y_{t-10} + \hat{\beta}_4 y_{t-11}

Value

An xts object defined by the output parameter.

References

James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.

See Also

yth_glm

Examples

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

Fits Hamilton's alternative model

Description

yth_glm fits a generalized linear model suggested by James D. Hamilton as a better alternative to the Hodrick-Prescott Filter.

Usage

yth_glm(x, h = 8, p = 4, ...)

Arguments

x

A univariate xts object of any zoo index class, such as Date, yearmon, or yearqtr. For converting objects of type timeSeries, ts, irts, fts, matrix, data.frame or zoo to xts, please read as.xts.

h

An integer, defining the lookahead period. Defaults to h = 8, suggested by Hamilton. The default assumes economic data of quarterly periodicity with a lookahead period of 2 years. This function is not limited by the default parameter, and Econometricians may change it as required.

p

An integer, indicating the number of lags. A Default of p = 4, suggested by Hamilton, assumes data is of quarterly periodicity. If data is of monthly periodicity, one may choose p = 12 or aggregate the series to quarterly periodicity and maintain the default. Econometricians should use this parameter to accommodate the Seasonality of their data.

...

all arguments passed to the function glm

Details

For time series of quarterly periodicity, Hamilton suggests parameters of h = 8 and p = 4, or an AR(4)AR(4) process, additionally lagged by 88 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.

yt+h=β0+β1yt+β2yt1+β3yt2+β4yt3+vt+hy_{t+h} = \beta_0 + \beta_1 y_t + \beta_2 y_{t-1} + \beta_3 y_{t-2} + \beta_4 y_{t-3} + v_{t+h}

v^t+h=yt+hβ^0+β^1yt+β^2yt1+β^3yt2+β^4yt3\hat{v}_{t+h} = y_{t+h} - \hat{\beta}_0 + \hat{\beta}_1 y_t + \hat{\beta}_2 y_{t-1} + \hat{\beta}_3 y_{t-2} + \hat{\beta}_4 y_{t-3}

Which can be rewritten as:

yt=β0+β1yt8+β2yt9+β3yt10+β4yt11+vty_{t} = \beta_0 + \beta_1 y_{t-8} + \beta_2 y_{t-9} + \beta_3 y_{t-10} + \beta_4 y_{t-11} + v_{t}

v^t=ytβ^0+β^1yt8+β^2yt9+β^3yt10+β^4yt11\hat{v}_{t} = y_{t} - \hat{\beta}_0 + \hat{\beta}_1 y_{t-8} + \hat{\beta}_2 y_{t-9} + \hat{\beta}_3 y_{t-10} + \hat{\beta}_4 y_{t-11}

Value

yth_glm returns a generalized linear model object of class glm, which inherits from lm.

References

James D. Hamilton. Why You Should Never Use the Hodrick-Prescott Filter. NBER Working Paper No. 23429, Issued in May 2017.

See Also

glm

Examples

data(GDPC1)

gdp_model <- yth_glm(GDPC1, h = 8, p = 4, family = gaussian)

summary(gdp_model)

plot(gdp_model)