Skip to content

whirldatascience/us-econometrics-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

us-econometrics-data

Fetching Econometrics data via API in R

API

Register and get API from www.bea.gov

require(XML) apiUrl<-"http://www.bea.gov/api/data/?&UserID=&method=GetData&datasetname=RegionalData&KeyCode=GDP_SP&GeoFIPS=STATE&ResultFormat=XML&Year=2010,2011,2012,2013,2014,2015" doc = xmlParse(apiUrl) Data = getNodeSet(doc, "//Results//Data") country<-sapply(Data, function(el) xmlGetAttr(el, "GeoName"))

gdp<-sapply(Data, function(el) xmlGetAttr(el, "DataValue")) year<-sapply(Data, function(el) xmlGetAttr(el, "TimePeriod"))

gdp_op<-data.frame(c(country)) gdp_op<-cbind(gdp_op,c(gdp),c(year))

write.csv(gdp_op,"gdp.csv",row.names=FALSE)

About

Fetching Econometrics data via API in R

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages