Skip to content

Instantly share code, notes, and snippets.

@Protonk
Created December 5, 2010 19:20
Show Gist options
  • Save Protonk/729369 to your computer and use it in GitHub Desktop.
Save Protonk/729369 to your computer and use it in GitHub Desktop.
Ended up not needing this for the previous post
library(WDI)
growth.df<-WDI(country="all",indicator="NY.GDP.MKTP.KD.ZG",start=1961,end=2009,extra=TRUE);
growth.df<-subset(growth.df,growth.df$region != "Aggregates")
growth.df<-growth.df[,c(2:4)]
names(growth.df)<-c("country","year","growth")
growth.df$country<-as.factor(growth.df$country)
#TS stuff
pre.ts<-cast(melt.data.frame(growth.df,id.vars=c("country","year")),year~country);
growth.ts<-ts(pre.ts,start=1961,end=2009,frequency=1)
diff.ts<-diff(growth.ts)
diff.mult<-as.data.frame(unclass(diff.ts))
diff.mult<-diff.mult[,-1]
diff.long<-melt(diff.mult)
diff.long$year<-rep(seq(1962,2009,1),213)
names(diff.long)<-c("country","diff","year")
diff.means<-ddply(diff.long,.(year),summarise,var=var(diff,na.rm=TRUE),mean=mean(diff,na.rm=TRUE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment