Skip to content

stefanangrick/BOJ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BOJ

CRAN_Status_Badge Cranlogs Downloads

The BOJ package provides an R interface to Bank of Japan statistics, specifically the flat files available on the BOJ Time-Series Data portal.

Installing the package

You can install the package from CRAN or GitHub.

library(devtools)
install_github("stefanangrick/BOJ")  # GitHub
install.packages("BOJ")              # CRAN

Example usage

To start using the package, load it into your R session.

library("BOJ")

Next, retrieve a list of available data sets using the get_boj_datasets() function.

ds <- get_boj_datasets()
head(ds)
## # A tibble: 6 × 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 Serv… sppi… http…
## 5 Flow of Funds                                                      fof   http…
## 6 Flow of Funds (with name of time-series, etc.)                     fof2… http…

The get_boj_datasets() function returns a tibble data frame listing available data sets. Use the url column as input for the get_boj() function to download, parse, and import the corresponding data set.

For example, to import monthly-frequency data on Japan’s Services Producer Price Index, use the following code:

sppi <- get_boj(ds$url[(ds$name == "sppi_m_en")])
head(sppi)
## # A tibble: 6 × 5
##   code              desc                                   struc date  obs_value
##   <chr>             <chr>                                  <chr> <chr>     <dbl>
## 1 PRCS20_5200000000 Services Producer Price Index (2020 b… [Bas… 2020…     101. 
## 2 PRCS20_5200000000 Services Producer Price Index (2020 b… [Bas… 2020…     101. 
## 3 PRCS20_5200000000 Services Producer Price Index (2020 b… [Bas… 2020…     101. 
## 4 PRCS20_5200000000 Services Producer Price Index (2020 b… [Bas… 2020…      99.4
## 5 PRCS20_5200000000 Services Producer Price Index (2020 b… [Bas… 2020…      98.8
## 6 PRCS20_5200000000 Services Producer Price Index (2020 b… [Bas… 2020…      99.3

To plot the data with ggplot2, run the following:

library("dplyr")
library("ggplot2")
library("zoo")

sppi_plot <- subset(sppi, code %in% c("PRCS20_5200000000", "PRCS20_5200010001",
                                      "PRCS20_5200010002", "PRCS20_5200010003",
                                      "PRCS20_5200010004", "PRCS20_5200010005",
                                      "PRCS20_5200010006", "PRCS20_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(title = "Services Producer Price Index", x = "Date", y = "Index") +
  theme(legend.title = element_blank())

Note that BOJ data sets use various time formats. The zoo package (e.g., as.yearmon()) can handle most of these formats.

Retrieving individual data series

To retrieve individual data series instead of full data sets, consider using the BOJfame package.

Note

This package is neither officially related to nor endorsed by the Bank of Japan. Please avoid overloading the BOJ servers with unnecessary requests.

About

R Interface to Bank of Japan Statistics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages