Skip to content

Instantly share code, notes, and snippets.

@Protonk
Created November 23, 2010 19:15
Show Gist options
  • Save Protonk/712327 to your computer and use it in GitHub Desktop.
Save Protonk/712327 to your computer and use it in GitHub Desktop.
WDI PPP start
#The following code requires a few packages to be installed, namely animation, WDI, and ggplot2.
#You can install them by typing install.packages("ggplot2"), inserting the package name. This
#requires an internet connection, because it is downloading a package from a mirror.
#Loads a library to access World Bank data automatically.
library(WDI);
#Loads a graphics library which makes nicer graphs than base R.
library(ggplot2);
#How does this change across years?
#Names the indicators so I don't need to type them in individually.
wdi.ind<-c("NY.GDP.PCAP.CD","NY.GDP.PCAP.PP.CD","NY.GDP.MKTP.CD");
#Loads up the data from the WDI API over the internet. Requires an internet connection
GDP.giant<-WDI(country="all",indicator=wdi.ind,start=1980,end=2009,extra=TRUE);
#Names the variables to something more tractable
names(GDP.giant)[4:6]<-c("GDP.per","GDP.PPP","GDP");
#Removes Aggregates (region averages).
GDP.giant<-subset(GDP.giant,GDP.giant$region != "Aggregates");
#Builds the dependent variable, lambda.
GDP.giant$lambda<-abs(GDP.giant$GDP.PPP-GDP.giant$GDP.per)/GDP.giant$GDP.per;
#Removes the US and Canada, both of which are pretty uninformative for us.
GDP.giant<-GDP.giant[which(GDP.giant$region != "North America"),];
#Changes region names into categorical variables and renames them slightly.
GDP.giant$region<-as.factor(GDP.giant$region);
levels(GDP.giant$region)<-c("East Asia & Pacific","Europe & Central Asia","Latin America\n& Caribbean","Middle East & N. Africa","South Asia","Sub-Saharan Africa");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment