我正在使用RWDI,该包允许通过其API导入世界银行数据。问题是我想查看该地区的所有国家/地区,例如撒哈拉以南非洲。但是为此,我需要指定许多国家(SSH现在为49)。

首先,这样做效率低下,特别是考虑到data.worldbank.org上的数据浏览器确实允许您选择区域。

但是,真正的问题是,对于(我猜是)世界银行API,要处理的国家/地区数量成问题,因为太多的国家/地区会产生HTTP错误。使我不得不将请求分为两部分。

但是,使用更有效的ALL值时,即使观察到的次数高得多,也不会出现错误。

现在,我的代码如下所示:

library(WDI)

COUNTRIES1 <- c( "AGO","BEN","BWA","BFA","BDI","CMR","CPV","CAF","TCD","COM","ZAR","COG","CIV","GNQ","ERI","ETH","GAB","GMB","GHA","GNB","GIN","KEN","LSO","LBR","MDG" )
COUNTRIES2 <- c( "MWI","MLI","MRT","MUS","MYT","MOZ","NAM","NER","NGA","RWA","STP","SEN","SYC","SLE","SOM","ZAF","SSD","SDN","SWZ","TZA","TGO","UGA","ZMB","ZWE" )
INDICATORS <- c("NY.GDP.PCAP.KN", "SP.DYN.TFRT.IN", "SP.POP.TOTL")

LONG1 <- WDI( country=COUNTRIES1, indicator=INDICATORS, start=1960, end=2009, extra=FALSE)
LONG2 <- WDI( country=COUNTRIES2, indicator=INDICATORS, start=1960, end=2009, extra=FALSE)

LONG <- merge( LONG1, LONG2, by=intersect( names(LONG1),names(LONG2) ), all=TRUE )

我尝试使用SSH作为国家/地区代码,但这给出了所有SSH国家/地区的汇总,而不是所有观察结果。

有任何想法吗?

最佳答案

您可以下载所有国家/地区的数据
并使用Region过滤结果。

library(WDI)
indicators <- c("NY.GDP.PCAP.KN", "SP.DYN.TFRT.IN", "SP.POP.TOTL")
d <- WDI("all", indicators, extra=TRUE, start=1960, end=2009)
# Discard unwanted rows
d <- d[ which(d$Region == "Sub-Saharan Africa"), ]
# Discard unwanted columns
d <- d[,1:6]
head(d)

关于r - 使用WDI包导入区域中所有国家的世界银行数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10191246/

10-13 08:00