Commit 0dcc26cb authored by Thomas Brand's avatar Thomas Brand

Adapt to new DBnomics API.

parent f2a4a4d5
......@@ -12,7 +12,9 @@ output: html_document
```{r, message=FALSE, warning=FALSE, echo=FALSE, results='hide'}
if (!"pacman" %in% installed.packages()[,"Package"]) install.packages("pacman")
pacman::p_load(tidyverse,magrittr,lubridate,knitr,rsdmx,zoo)
pacman::p_load(tidyverse,magrittr,lubridate,knitr,rsdmx,zoo,devtools)
#install_github("dbnomics/rdbnomics")
pacman::p_load_gh("dbnomics/rdbnomics")
opts_chunk$set(message=FALSE, warning=FALSE, cache=FALSE)
......@@ -57,13 +59,11 @@ We take data directly from <a href="https://db.nomics.world/" target="_blank">DB
We download loans series from the Bank of International Settlements.
```{r}
url_dbnomics <- "https://api.db.nomics.world/api/v1/sdmx"
# List of available countries in BIS data
EAtot_code <- c("DE", "FI", "FR", "IT", "PT", "AT",
"GR", "IE", "NL", "BE", "ES", "XM")
url_country <- paste0(EAtot_code, collapse = "+")
url <- paste0(url_dbnomics,"/BIS/data/CNFS/Q.",url_country,".N+H.A.M.XDC.A")
filter <- paste0("Q.",url_country,".N+H.A.M.XDC.A")
# N or H: Borrowing sector : NFC or Households
# A: Lending sector : All
......@@ -71,15 +71,14 @@ url <- paste0(url_dbnomics,"/BIS/data/CNFS/Q.",url_country,".N+H.A.M.XDC.A")
# XDC: Unit type: Domestic currency
# A: Adjustment : Adjustment for breaks
data_sdmx <- readSDMX(url)
df <- as_tibble(data_sdmx)
df <- rdb("BIS","CNFS",mask = filter)
loans <- df %>%
select(TIME_PERIOD, WIDUKIND_ID, OBS_VALUE, `BORROWERS-COUNTRY`, WIDUKIND_NAME) %>%
rename(time = TIME_PERIOD,
var = WIDUKIND_ID,
values = OBS_VALUE,
country = `BORROWERS-COUNTRY`) %>%
select(period, series_code, value, `borrowers-country`, series_name) %>%
rename(time = period,
var = series_code,
values = value,
country = `borrowers-country`) %>%
mutate(time=as.Date(as.yearqtr(gsub("Q","",time))),
values=ifelse(values=="",NA,values),
values = as.numeric(values)) %>%
......@@ -91,15 +90,15 @@ loans_nfc <- loans %>%
filter(substr(var,6,6)=="N") %>%
mutate(var="loans_nfc")
varname_nfc <- unique(as.character(filter(loans_nfc,country == "XM")$WIDUKIND_NAME))
loans_nfc %<>% select(-WIDUKIND_NAME)
varname_nfc <- unique(as.character(filter(loans_nfc,country == "XM")$series_name))
loans_nfc %<>% select(-series_name)
loans_hh <- loans %>%
filter(substr(var,6,6)=="H") %>%
mutate(var=as.factor("loans_hh"))
varname_hh <- unique(as.character(filter(loans_hh,country == "XM")$WIDUKIND_NAME))
loans_hh %<>% select(-WIDUKIND_NAME)
varname_hh <- unique(as.character(filter(loans_hh,country == "XM")$series_name))
loans_hh %<>% select(-series_name)
```
We can check the first date available for loans to non-financial corporations and to households (XM stands for Euro area).
......@@ -296,16 +295,15 @@ To build long series of lending rate, we use historical data from the Internatio
# Download lending rates of the 8 countries from IFS
country_code <- c("BE","FR","DE","IT","NL","FI","IE","ES")
url_country <- paste0(country_code, collapse = "+")
url <- paste0(url_dbnomics,"/IMF/data/IFS/Q.",url_country,".FILR-PA")
filter <- paste0("Q.",url_country,".FILR_PA")
data_sdmx <- readSDMX(url)
df <- as_tibble(data_sdmx)
df <- rdb("IMF","IFS",mask = filter)
lendingrate_bycountry <- df %>%
select(`REF-AREA`,TIME_PERIOD, OBS_VALUE) %>%
rename(time = TIME_PERIOD,
values = OBS_VALUE,
country = `REF-AREA`) %>%
select(REF_AREA,period, value) %>%
rename(time = period,
values = value,
country = REF_AREA) %>%
mutate(values = as.numeric(values),
time=as.Date(as.yearqtr(gsub("Q","",time)))) %>%
filter(year(time)>=1985)
......@@ -313,6 +311,7 @@ lendingrate_bycountry <- df %>%
# Download PPP GDP of the 8 countries from WEO
country_iso <- c("BEL","FRA", "DEU", "ITA", "NLD", "FIN", "IRL", "ESP")
url_country_iso <- paste0(country_iso, collapse = "+")
url_dbnomics <- "https://api.db.nomics.world/api/v1/sdmx"
url <- paste0(url_dbnomics,"/IMF/data/WEO/PPPGDP.",url_country_iso,".5")
data_sdmx <- readSDMX(url)
......@@ -349,20 +348,16 @@ lendingrate_old <-
# Bank interest rates - loans to corporations (new business) - euro area Euro area (changing composition), Annualised agreed rate (AAR) / Narrowly defined effective rate (NDER), Credit and other institutions (MFI except MMFs and central banks) reporting sector - Loans other than revolving loans and overdrafts, convenience and extended credit card debt [A20-A2Z], Total initial rate fixation, Total amount, New business coverage, Non-Financial corporations (S.11) sector, denominated in Euro
url_series <- "/ECB/data/MIR/M.U2.B.A2A.A.R.A.2240.EUR.N"
url <- paste0(url_dbnomics, url_series)
df <- rdb(ids="ECB/MIR/M.U2.B.A2A.A.R.A.2240.EUR.N")
data_sdmx <- readSDMX(url)
df <- as_tibble(data_sdmx)
varname <- unique(as.character(df$WIDUKIND_NAME))
varname <- unique(as.character(df$series_name))
lendingrate_recent <- df %>%
mutate(year = substr(TIME_PERIOD,1,4),
month = substr(TIME_PERIOD,6,7),
mutate(year = substr(period,1,4),
month = substr(period,6,7),
time= as.Date(as.yearqtr(paste0(year,"-",month,"-","01"),format="%Y-%m-%d"))) %>%
select(time, OBS_VALUE) %>%
rename(values= OBS_VALUE) %>%
select(time, value) %>%
rename(values= value) %>%
mutate(values= as.numeric(values)) %>%
group_by(time) %>%
summarize(values=mean(values)) %>%
......@@ -412,20 +407,16 @@ longrate_old <-
# Long term interest rate Euro area 19 (fixed composition), Long-term interest rate for convergence purposes - Unspecified rate type, Debt security issued, 10 years maturity, New business coverage, denominated in Euro - Unspecified counterpart sector
url_series <- "/ECB/data/IRS/M.I8.L.L40.CI.0000.EUR.N.Z"
url <- paste0(url_dbnomics, url_series)
df <- rdb(ids="ECB/IRS/M.I8.L.L40.CI.0000.EUR.N.Z")
data_sdmx <- readSDMX(url)
df <- as_tibble(data_sdmx)
varname <- unique(as.character(df$WIDUKIND_NAME))
varname <- unique(as.character(df$series_name))
longrate_recent <- df %>%
mutate(year = substr(TIME_PERIOD,1,4),
month = substr(TIME_PERIOD,6,7),
mutate(year = substr(period,1,4),
month = substr(period,6,7),
time= as.Date(as.yearqtr(paste0(year,"-",month,"-","01"),format="%Y-%m-%d"))) %>%
select(time, OBS_VALUE) %>%
rename(values= OBS_VALUE) %>%
select(time, value) %>%
rename(values= value) %>%
mutate(values= as.numeric(values)) %>%
select(values, time) %>%
group_by(time) %>%
......@@ -459,18 +450,14 @@ The entrepreunarial networth is approximated through the Dow Jones index for the
```{r, fig.align="center"}
# Dow Jones euro Euro area (changing composition) - Equity/index - Dow Jones Euro Stoxx Price Index - Historical close, average of observations through period - Euro
url_series <- "/ECB/data/FM/Q.U2.EUR.DS.EI.DJEURST.HSTA"
url <- paste0(url_dbnomics, url_series)
data_sdmx <- readSDMX(url)
df <- as_tibble(data_sdmx)
df <- rdb(ids="ECB/FM/Q.U2.EUR.DS.EI.DJEURST.HSTA")
varname <- unique(as.character(df$WIDUKIND_NAME))
varname <- unique(as.character(df$series_name))
networth <- df %>%
select(OBS_VALUE, TIME_PERIOD) %>%
rename(time= TIME_PERIOD,
values= OBS_VALUE) %>%
select(value, period) %>%
rename(time= period,
values= value) %>%
mutate(time=as.Date(as.yearqtr(gsub("Q","",time))),
values= as.numeric(values),
var = as.factor("networth"))
......@@ -493,18 +480,14 @@ varname
```{r, fig.align="center"}
# House price Euro area 19 (fixed composition); Residential property prices, New and existing dwellings; Residential property in good and poor condition; Whole country; Neither seasonally nor working day adjusted; ECB
url_series <- "/ECB/data/RPP/Q.I8.N.TD.00.3.00"
url <- paste0(url_dbnomics, url_series)
df <- rdb(ids="ECB/RPP/Q.I8.N.TD.00.3.00")
data_sdmx <- readSDMX(url)
df <- as_tibble(data_sdmx)
varname <- unique(as.character(df$WIDUKIND_NAME))
varname <- unique(as.character(df$series_name))
houseprice<- df %>%
select(OBS_VALUE, TIME_PERIOD) %>%
rename(time= TIME_PERIOD,
values= OBS_VALUE) %>%
select(value, period) %>%
rename(time= period,
values= value) %>%
mutate(time=as.Date(as.yearqtr(gsub("Q","",time))),
values= as.numeric(values),
var = as.factor("houseprice"))
......@@ -606,13 +589,12 @@ EA_CMR_rawdata <-
EA_SW_rawdata %>%
gather(var, values, -time) %>%
bind_rows(EA_Finance_data) %>%
filter(time <= min(minmaxDateRaw,minmaxDateFinance),
filter(#time <= min(minmaxDateRaw,minmaxDateFinance),
time >= "1980Q1") %>%
spread(key = var, value = values)
EA_CMR_rawdata %>%
write.csv("EA_CMR_rawdata.csv", row.names=FALSE)
```
Then data are normalized by capita and price if needed. Eventually we have 14 series : the 12 series similar to [@Chri14a] plus loans to households and house price series.
......@@ -636,7 +618,7 @@ EA_CMR_data <-
creditspread = (lendingrate - shortrate)/100)
EA_CMR_data %>%
na.omit() %>%
#na.omit() %>%
write.csv("EA_CMR_data.csv", row.names=FALSE)
```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment