The BOJ
package
provides an R
interface to Bank of Japan statistics, specifically
the flat
files available on the BOJ Time-Series Data
portal.
To import data, first load the package:
Next, run the get_boj_datasets()
function to obtain a
list of available data sets:
datasets <- get_boj_datasets()
datasets
## # A tibble: 16 × 3
## desc name url
## <chr> <chr> <chr>
## 1 "Corporate Goods Price Index (CGPI)" cgpi… http…
## 2 "Producer Price Index using chain-weighted index formula" cgpi… http…
## 3 "Services Producer Price Index (SPPI)" sppi… http…
## 4 "Wholesale Services Price Index, and Research and development Se… sppi… http…
## 5 "Flow of Funds" fof http…
## 6 "Flow of Funds (with name of time-series, etc.)" fof2… http…
## 7 "TANKAN" co http…
## 8 "TANKAN (Fixed Investment and Software Investment)(Compiled unde… cole… http…
## 9 "Balance of Payments " bp_m… http…
## 10 "Regional Balance of Payments (quarterly)" regb… http…
## 11 "International Investment Position (Quarterly Data) & Gross Exte… qiip… http…
## 12 "International Investment Position (Calendar Year Data)" iip_… http…
## 13 "BIS International Locational Banking Statistics in Japan (Claim… bis1… http…
## 14 "BIS International Locational Banking Statistics in Japan (Liabi… bis1… http…
## 15 "BIS International Consolidated Banking Statistics in Japan (Imm… bis2… http…
## 16 "BIS International Consolidated Banking Statistics in Japan (Ult… bis2… http…
The function returns a tibble data frame listing the
available data sets. The column url
can be used as input
for the function get_boj()
which downloads, parses and
imports the corresponding data.
To import monthly-frequency data on Japan’s Services Producer Price Index, run:
sppi <- get_boj(datasets$url[(datasets$name == "sppi_m_en")])
sppi
## # A tibble: 29,241 × 5
## code desc struc date obs_value
## <chr> <chr> <chr> <chr> <dbl>
## 1 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 101.
## 2 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 101.
## 3 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 101.
## 4 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 99.4
## 5 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 98.8
## 6 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 99.3
## 7 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 99.7
## 8 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 99.7
## 9 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 99.9
## 10 PRCS20_5200000000 Services Producer Price Index (2020 … [Bas… 2020… 100.
## # ℹ 29,231 more rows
To plot the data using ggplot2, run the following:
library("dplyr")
library("ggplot2")
library("zoo")
sppi_plot <- subset(sppi, code %in% c("PRCS15_5200000000", "PRCS15_5200010001",
"PRCS15_5200010002", "PRCS15_5200010003",
"PRCS15_5200010004", "PRCS15_5200010005",
"PRCS15_5200010006", "PRCS15_5200010007"))
sppi_plot <- mutate(sppi_plot, date = as.Date(as.yearmon(date, format = "%Y%m")))
sppi_plot <- mutate(sppi_plot, struc = gsub("^Major group/ ", "", struc))
sppi_plot <- subset(sppi_plot, !is.na(obs_value))
ggplot(sppi_plot, aes(x = date, y = obs_value)) +
geom_line(aes(colour = struc)) +
labs(x = "Date", y = "Services Producer Price Index (2015 base)") +
theme(legend.title = element_blank())
Note that BOJ data sets come with a number of different time formats.
The zoo package
(e.g. as.yearmon()
) should be able to parse most
formats.
This package is in no way officially related to or endorsed by the Bank of Japan. It was inspired by the BIS R package. Please don’t abuse the BOJ’s servers with unnecessary calls.