Hello, Is there a function in R that calculates the year-on-year growth rate of some time series? In EView the function is @pchy. Thanks, miao [[alternative HTML version deleted]]
On 06-04-2012, at 10:27, jpm miao wrote:> Hello, > > Is there a function in R that calculates the year-on-year growth rate of > some time series? > > In EView the function is @pchy.This might do what you need pchy <- function(x) { if(!is.ts(x)) stop("x is not a timeseries") x.freq <- tsp(x)[3] if(!(x.freq %in% c(1,2,4,12))) stop("Invalid frequency of timeseries x (must be 1, 2, 4, 12)") y <- diff(x,lag=x.freq)/lag(x,-x.freq) return(y) } Berend