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

Update with new DBnomics API.

parent 8841c8d0
---
Title: Reproduce some results of Schorfheide (2000)
date: 2016-07-02
Category: Model
Tags: DSGE, bayesian estimation, R
Slug: fs2000
Author: Thomas Brand
Summary: Reproduce some results of Schorfheide (2000) with Dynare, through bayesian estimation of a cash-in-advance model, with an updated database.
Download: https://git.nomics.world/macro/fs2000
output: html_document
output:
html_document:
toc: false
bibliography: fs2000.bib
---
```{r, message=FALSE, warning=FALSE, echo=FALSE, results='hide'}
if (!"pacman" %in% installed.packages()[,"Package"]) install.packages("pacman", repos='http://cran.r-project.org')
pacman::p_load(curl,tidyverse,magrittr,lubridate,knitr,rsdmx,zoo,R.matlab,stringr)
pacman::p_load(tidyverse,magrittr,lubridate,knitr,zoo,R.matlab,stringr)
pacman::p_load_gh("dbnomics/rdbnomics")
opts_chunk$set(message=FALSE, warning=FALSE, cache=FALSE, comment=NA)
# theme for ggplot
theme <- theme_bw()+ theme(strip.background=element_blank(),
strip.text=element_text(size=15),
title=element_text(size=16),
......@@ -32,74 +27,41 @@ matlab_path <- '/usr/local/MATLAB/R2015b/bin/matlab'
dynare_path <- '/usr/local/dynare/matlab/'
```
This post replicates the estimation of the cash in advance model (termed M1 in the paper) described in @Scho00, with updated data. This implementation was written by Michel Juillard and is given in the `examples` folder of Dynare.
This post replicates the estimation of the cash in advance model described in @Scho00 (termed M1 in the paper), with updated data. This implementation was written by Michel Juillard and is given in the `examples` folder of [Dynare](http://www.dynare.org/).
# Data
The data are retrieved directly through DBnomics and are stocked in `fs2000_data.csv`. They are therefore different from the original dataset used by @Scho00.
The data are retrieved directly through [DBnomics](https://db.nomics.world/) and are stocked in `fs2000_data.csv`. They are therefore different from the original dataset used by @Scho00.
```{r}
url_dbnomics <- "https://api.db.nomics.world/api/v1/sdmx"
url_provider <- "/BEA/data"
url_dataset_series <- "/nipa-section1-10106-q/A191RX1.Q"
# Real Gross Domestic Product, unit : billions 2009 $, SA annual rate
url <- paste0(url_dbnomics,url_provider,url_dataset_series)
data_sdmx <- readSDMX(url)
df_gdp <- data.frame(data_sdmx, var="gdp")
url_dataset_series <- "/nipa-section1-10109-q/A191RD3.Q"
# Gross Domestic Product: Implicit Price Deflator, SA
url <- paste0(url_dbnomics,url_provider,url_dataset_series)
data_sdmx <- readSDMX(url)
df_defgdp <- data.frame(data_sdmx, var="defgdp")
bea_data <-
rbind(df_gdp,df_defgdp) %>%
select(var, TIME_PERIOD, OBS_VALUE) %>%
rename(time = TIME_PERIOD,
values = OBS_VALUE) %>%
mutate(time=as.Date(as.yearqtr(time,format="%YQ%q")),
values=as.numeric(values))
url_provider <- "/OECD/data"
url_dataset_series <- "/MEI/USA.LFWA64TT.STSA.Q"
# unit: 1000 person (source: OECD, MEI)
url <- paste0(url_dbnomics,url_provider,url_dataset_series)
data_sdmx <- readSDMX(url)
df_pop <- data.frame(data_sdmx, var="pop")
pop <-
df_pop %>%
select(var, TIME_PERIOD, OBS_VALUE) %>%
rename(time = TIME_PERIOD,
values = OBS_VALUE) %>%
mutate(time=as.Date(as.yearqtr(time,format="%Y-Q%q")),
values=as.numeric(values))
rawdata <- rbind(bea_data,pop)
fs2000_data <-
rawdata %>%
spread(key = var, value = values) %>%
transmute(time=time,
gdp_rpc=1e+9*gdp/pop,
defgdp = defgdp,
gyObs = gdp_rpc/lag(gdp_rpc),
gpObs = defgdp/lag(defgdp))
fs2000_data %>%
transmute(time=gsub(" ","",as.yearqtr(time)),
gyObs,
gpObs) %>%
na.omit() %>%
gdp_rpc <- rdb(ids="BEA/NIPA-T70100/A939RX-Q") %>%
mutate(var="gdp_rpc")
defgdp <- rdb(ids="BEA/NIPA-T10109/A191RD-Q") %>%
mutate(var="defgdp")
fs2000_rawdata <-
bind_rows(gdp_rpc,defgdp) %>%
select(var, period, value) %>%
spread(var, value) %>%
arrange(period) %>%
mutate(gyObs=log(gdp_rpc)-log(lag(gdp_rpc)),
gpObs=log(defgdp)-log(lag(defgdp)))
fs2000_data <-
fs2000_rawdata %>%
transmute(time=gsub(" ","",as.yearqtr(period)),
gyObs=1+gyObs,
gpObs=1+gpObs) %>%
na.omit()
fs2000_data %>%
write.csv("fs2000_data.csv", row.names=FALSE)
```
# Model
The equations are taken from @Naso94. Note that there is an initial minus sign missing in equation (A1), p. S63. The prior distribution follows the one originally specified in Schorfheide's paper. Note that the $\beta$ prior for $\rho$ implies an asymptote and corresponding prior mode for $\rho$ at 0. It is generally recommended to avoid this extreme type of prior.
The equations are taken from @Naso94. Note that there is an initial minus sign missing in equation (A1), p. S63. The prior distribution follows the one originally specified in Schorfheide's paper. Note that the Beta prior for $\rho$ implies an asymptote and corresponding prior mode for $\rho$ at 0. It is generally recommended to avoid this extreme type of prior.
## Preamble
```{r}
......
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