library(openxlsx) excel_sample1<-read.xlsx("http://kanggc.iptime.org/book/data/sample1-n.xlsx") year<-excel_sample1$year gdp<-excel_sample1$gdp consumption<-excel_sample1$consumption graphics.off() par("mar") par(mar=c(1,1,1,1)) y.ts<-ts(gdp, start=2000, end=2016, frequency=1) c.ts<-ts(consumption, start=2000, end=2016, frequency=1) lagy<-lag(y.ts, k=-1) lagc<-lag(c.ts, k=-1) gy<-(y.ts-lagy)/lagy gc<-(c.ts-lagc)/lagc ly.ts<-log(y.ts) lc.ts<-log(c.ts) gly<-ly.ts-lag(ly.ts, k=-1) glc<-lc.ts-lag(lc.ts, k=-1) (y<-cbind(gy, gly)) (c<-cbind(gc, glc)) par(mfrow=c(2,1)) plot(gy, type="l", col="red", main="Exact Growth Rate vs. Approx. Growth Rate of GDP") lines(gly, lwd=3, lty=6, col="green") plot(gc, type="l", col="red", main="Exact Growth Rate vs. Approx. Growth Rate of Consumption") lines(glc, lwd=3, lty=6, col="green")