**TimeSeriesIreland » R**, and kindly contributed to R-bloggers)

One prominent feature of early degree-level macroeconomics courses is the concept of ‘potential output’, which one could roughly define as the level of output (GDP) at which inflation is not ‘accelerating’. Potential output is of interest to macroeconomists when analysing the question of output gaps and macroeconomic stabilisation policies by governments, whether that be in a ‘boom’ or a recession. If a country has a positive output gap, we can say that the economy is operating above potential and inflationary pressures will build up, as factors of production begin to demand ever higher prices to be brought into use; and vice versa.

How one actually measures ‘the’ output gap is not quite as straightforward as the Principles of Economics texbooks let on, and there’s little agreement among economists as to what constitutes the ‘best’ measure of the output gap. Usually, output gap series provided by government statistical agencies arise from one of two estimation procedures: first, one could use a production function, *e.g.,* , to estimate the corresponding from , , and . Second, one could use the estimated trend of the output series as implied by a filter or the residuals from a regression on time. In practice, the first method often utilises the second to build potential series for the labour component of the production function. I will focus on the second of these approaches, for now. I define the output gap as the log deviation from potential output; log deviations are more intuitive, as they roughly correspond to a percentage deviation from potential output.

The most commonly used method to estimate the trend in ouput is the Hodrick-Prescott (H-P) filter; here, we want to minimise the trend component, , of a series Y: ,

.

where is the difference operator and is a smoothing parameter; as , the H-P corresponds to a linear trend model. For quarterly data, is a commonly used value.

Another way to estimate the trend is with a regression of Y on a polynomial of time, *e.g.,* , . A linear trend model is simply a regression of the form ; a quadratic trend model is ; and so on.

To illustrate these techniques, I show what they imply for real and nominal gross domestic product (GDP) and gross national product (GNP). The two images below graph Irish nominal (first) and real (second) GDP and GNP from 1997 to 2010 (click to make them larger).

The two graphs below show output gaps for nominal and real GDP based on a H-P filter (), linear trend, quadratic trend, and cubic trend.

The final two graphs show output gaps for nominal and real GNP.

The gap implied by a simple linear trend is far greater in every case, while the gaps implied by quadratic trend, cubic trend, and the H-P filter are very similar.

Below is some R code for a function that will produce output gaps (as measured by a H-P filter, and linear, quadratic, and cubic time trends).

function(data,l=1600){ #h-p filter code from Farnsworth hpfilterq <- function(x=data,lambda=l){ eye <- diag(length(x)) result <- solve(eye+lambda*crossprod(diff(eye,lag=1,d=2)),x) return(result) } hpfiltered<-hpfilterq(data) hpgap <- data - hpfiltered # t1<-1:length(data) t2<-t1^2 t3<-t1^3 t1<-ts(t1) t2<-ts(t2) t3<-ts(t3) # datats<-ts(data) myseries<-ts.union(datats,t1,t2,t3) # polynomial1 <- lm(datats ~ t1,data=myseries) polynomial2 <- lm(datats ~ t1 + t2,data=myseries) polynomial3 <- lm(datats ~ t1 + t2 + t3,data=myseries) # returndata<-data.frame(hpgap,polynomial1$residuals,polynomial2$residuals,polynomial3$residuals) colnames(returndata) <- c("H-P Gap", "Poly1","Poly2","Poly3") return(returndata) }

**leave a comment**for the author, please follow the link and comment on their blog:

**TimeSeriesIreland » R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...