GDP SERIES # “A191RC”
library(bea.R)
## Loading required package: data.table
## Creating a generic function for 'toJSON' from package 'jsonlite' in package 'googleVis'
## Note: As of February 2018, beaGet() requires 'TableName' for NIPA and NIUnderlyingDetail data instead of 'TableID.' See https://github.us-bea/bea.R for details.
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2
## ──
## ✔ ggplot2 3.4.0 ✔ purrr 1.0.1
## ✔ tibble 3.1.8 ✔ dplyr 1.1.0
## ✔ tidyr 1.3.0 ✔ stringr 1.5.0
## ✔ readr 2.1.3 ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::between() masks data.table::between()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::first() masks data.table::first()
## ✖ dplyr::lag() masks stats::lag()
## ✖ dplyr::last() masks data.table::last()
## ✖ purrr::transpose() masks data.table::transpose()
library(ggplot2)
library(dplyr)
beaKey <- "3EA4F816-4E52-48F1-AB1F-E1608E82056F"
beaSets( beaKey = beaKey)
## No encoding supplied: defaulting to UTF-8.
## $Dataset
## DatasetName DatasetDescription
## 1 NIPA Standard NIPA tables
## 2 NIUnderlyingDetail Standard NI underlying detail tables
## 3 MNE Multinational Enterprises
## 4 FixedAssets Standard Fixed Assets tables
## 5 ITA International Transactions Accounts
## 6 IIP International Investment Position
## 7 InputOutput Input-Output Data
## 8 IntlServTrade International Services Trade
## 9 GDPbyIndustry GDP by Industry
## 10 Regional Regional data sets
## 11 UnderlyingGDPbyIndustry Underlying GDP by Industry
## 12 APIDatasetMetaData Metadata about other API datasets
##
## attr(,"params")
## ParameterName ParameterValue
## 1 USERID 3EA4F816-4E52-48F1-AB1F-E1608E82056F
## 2 METHOD GETDATASETLIST
## 3 RESULTFORMAT JSON
beaParams ( beaKey= beaKey, 'NIPA')
## No encoding supplied: defaulting to UTF-8.
## $Parameter
## ParameterName ParameterDataType
## 1 Frequency string
## 2 ShowMillions string
## 3 TableID integer
## 4 TableName string
## 5 Year integer
## ParameterDescription
## 1 A - Annual, Q-Quarterly, M-Monthly
## 2 A flag indicating that million-dollar data should be returned.
## 3 The standard NIPA table identifier
## 4 The new NIPA table identifier
## 5 List of year(s) of data to retrieve (X for All)
## ParameterIsRequiredFlag ParameterDefaultValue MultipleAcceptedFlag AllValue
## 1 1 1
## 2 0 N 0
## 3 0 <NA> 0
## 4 0 <NA> 0
## 5 1 1 X
##
## attr(,"params")
## ParameterName ParameterValue
## 1 USERID 3EA4F816-4E52-48F1-AB1F-E1608E82056F
## 2 METHOD GETPARAMETERLIST
## 3 DATASETNAME NIPA
## 4 RESULTFORMAT JSON
beaSearch ('Gross Domestic Product', beaKey)
## Creating first-time local copy of metadata for all datasets - only done once.
## Datasets will be updated only if timestamps indicate metadata obsolete in future searches,
## and only obsolete metadata sets will be updated (it's faster this way).
##
## No encoding supplied: defaulting to UTF-8.
## Warning in beaSearch("Gross Domestic Product", beaKey): Regional metadata is
## missing from
## /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/beaR/data
## and may be locked for updating on the BEA API; searching national metadata
## only.
## SeriesCode RowNumber LineDescription LineNumber
## 1: A191RL 10 Gross domestic product 1
## 2: A009RL 100 Structures 10
## 3: Y033RL 110 Equipment 11
## 4: Y001RL 120 Intellectual property products 12
## 5: A011RL 130 Residential 13
## ---
## 2438: B935RY 70 Private fixed investment 5
## 2439: SWSNXY 80 Net exports 6
## 2440: SWSHXY 90 Exports 7
## 2441: SWSHMY 100 Imports 8
## 2442: SWSHGY 110 Government 9
## ParentLineNumber Tier Path TableID DatasetName
## 1: 0 1 T10101 NIPA
## 2: 0 10 T10101 NIPA
## 3: 0 11 T10101 NIPA
## 4: 0 12 T10101 NIPA
## 5: 0 13 T10101 NIPA
## ---
## 2438: 0 5 U90500 NIUnderlyingDetail
## 2439: 0 6 U90500 NIUnderlyingDetail
## 2440: 0 7 U90500 NIUnderlyingDetail
## 2441: 0 8 U90500 NIUnderlyingDetail
## 2442: 0 9 U90500 NIUnderlyingDetail
## TableName
## 1: Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product
## 2: Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product
## 3: Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product
## 4: Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product
## 5: Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product
## ---
## 2438: Table 9.5U. Contributions to Percent Change in Real Gross Domestic Product From Final Sales of Computers, Software, and Communications Equipment
## 2439: Table 9.5U. Contributions to Percent Change in Real Gross Domestic Product From Final Sales of Computers, Software, and Communications Equipment
## 2440: Table 9.5U. Contributions to Percent Change in Real Gross Domestic Product From Final Sales of Computers, Software, and Communications Equipment
## 2441: Table 9.5U. Contributions to Percent Change in Real Gross Domestic Product From Final Sales of Computers, Software, and Communications Equipment
## 2442: Table 9.5U. Contributions to Percent Change in Real Gross Domestic Product From Final Sales of Computers, Software, and Communications Equipment
## ReleaseDate NextReleaseDate MetaDataUpdated Account
## 1: Feb 28 2019 8:30AM Mar 28 2019 8:30AM 2019-03-06T10:13:29.923 National
## 2: Feb 28 2019 8:30AM Mar 28 2019 8:30AM 2019-03-06T10:13:29.923 National
## 3: Feb 28 2019 8:30AM Mar 28 2019 8:30AM 2019-03-06T10:13:29.923 National
## 4: Feb 28 2019 8:30AM Mar 28 2019 8:30AM 2019-03-06T10:13:29.923 National
## 5: Feb 28 2019 8:30AM Mar 28 2019 8:30AM 2019-03-06T10:13:29.923 National
## ---
## 2438: Jul 31 2018 8:30AM Jan 1 1900 12:00AM 2019-03-06T10:13:32.840 National
## 2439: Jul 31 2018 8:30AM Jan 1 1900 12:00AM 2019-03-06T10:13:32.840 National
## 2440: Jul 31 2018 8:30AM Jan 1 1900 12:00AM 2019-03-06T10:13:32.840 National
## 2441: Jul 31 2018 8:30AM Jan 1 1900 12:00AM 2019-03-06T10:13:32.840 National
## 2442: Jul 31 2018 8:30AM Jan 1 1900 12:00AM 2019-03-06T10:13:32.840 National
## apiCall
## 1: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIPA', 'TableName' = 'T10101', ...))
## 2: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIPA', 'TableName' = 'T10101', ...))
## 3: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIPA', 'TableName' = 'T10101', ...))
## 4: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIPA', 'TableName' = 'T10101', ...))
## 5: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIPA', 'TableName' = 'T10101', ...))
## ---
## 2438: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIUnderlyingDetail', 'TableName' = 'U90500', ...))
## 2439: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIUnderlyingDetail', 'TableName' = 'U90500', ...))
## 2440: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIUnderlyingDetail', 'TableName' = 'U90500', ...))
## 2441: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIUnderlyingDetail', 'TableName' = 'U90500', ...))
## 2442: beaGet(list('UserID' = '[your_key]', 'Method' = 'GetData', 'DatasetName' = 'NIUnderlyingDetail', 'TableName' = 'U90500', ...))
beaSearch('gross domestic product', asHtml = TRUE)
## Warning in beaSearch("gross domestic product", asHtml = TRUE): Searching without specifying beaKey, e.g.,
## beaSearch("tobacco", beaKey = "[your 36-character API key]")
## is not recommended, as the key is needed to update locally stored metadata.
## Creating first-time local copy of metadata for all datasets - only done once.
## Datasets will be updated only if timestamps indicate metadata obsolete in future searches,
## and only obsolete metadata sets will be updated (it's faster this way).
##
## Warning in bea.R::beaGet(beaMetaSpecs, asList = FALSE, asTable = FALSE, :
## Invalid API key of class NULL
## Warning in beaUpdateMetadata(beaKnownMetaSets, beaKey): API metadata not
## returned. Verify that you are using a valid API key, represented as a
## character string.
## Warning in beaSearch("gross domestic product", asHtml = TRUE): Regional
## metadata is missing from
## /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/beaR/data
## and may be locked for updating on the BEA API; searching national metadata
## only.
?beaGet
specs <- (list('UserID' = beaKey,
'Method' = 'GetData',
'DatasetName' = 'NIPA',
'TableName' = 'T10101',
'Frequency' = 'A',
'Year' = 'X'
))
df <- beaGet(specs)
## No encoding supplied: defaulting to UTF-8.
df2 <- beaGet((list('UserID' = beaKey,
'Method' = 'GetData',
'DatasetName' = 'NIPA',
'TableName' = 'T10101',
'Frequency' = 'A',
'Year' = 'X')
))
## No encoding supplied: defaulting to UTF-8.
df2 <- slice(df2, 1)
df2_long <- pivot_longer(data = df2,
cols = starts_with('DataValue'),
names_to = "years",
values_to = "GDP")
df2_sub <- df2_long[70:93,]
df2_sub
## # A tibble: 24 × 9
## TableName SeriesCode LineNumber LineDes…¹ METRI…² CL_UNIT UNIT_…³ years GDP
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
## 1 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 4.8
## 2 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 4.1
## 3 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 1
## 4 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 1.7
## 5 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 2.8
## 6 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 3.9
## 7 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 3.5
## 8 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 2.8
## 9 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 2
## 10 T10101 A191RL 1 Gross do… Fisher… Percen… 0 Data… 0.1
## # … with 14 more rows, and abbreviated variable names ¹LineDescription,
## # ²METRIC_NAME, ³UNIT_MULT
library(stringr)
df2_sub <- df2_sub %>%
mutate(years = str_remove(years, "DataValue_"))
ggplot(data = df2_sub, aes(x = years, y = GDP)) +
geom_point() +
labs(title= "Changes of GDP growth rate over the past two decades",
x = "Years", y = "GDP growth percentage")