83 views

Uploaded by Rene Barrera

Bvarsv Replication

- Programs
- IT430 Assignment 3 Calculator
- LPinMatlab2012
- mysqllab.txt
- Pre-3A
- Stack
- Lesson 11
- Microarray time series
- Cost Sheet Dump
- Non Dominated Sorting
- F2L Feliks Zemdegs
- Computer Notes - Data Structures - 31
- winter c++
- Ant Colony Optimization Aco for the Traveling Salesman Problem Tsp Using Partitioning
- Visual Vasic
- PresentationOM.pptx
- KNX Telegram Definitions
- ch03.pdf
- Código Macros Mover-objetos en Power Point
- Programme Specification for CS 2012

You are on page 1of 13

November 26, 2015

This code uses the R package bvarsv (https://github.com/FK83/bvarsv) to replicate several figures from Del

Negro and Primiceri (Time Varying Structural Vector Autoregressions and Monetary Policy: A Corrigendum,

Review of Economic Studies 82, 1342-1345, 2015.) The figures appear in the online appendix for the paper,

which is openly available at http://restud.oxfordjournals.org/content/82/4/1342/suppl/DC1. Note that the

MCMC algorithm implemented in bvarsv is called Algorithm 2 by Del Negro and Primiceri (2015).

# Load package

library(bvarsv)

# Fix random seed

set.seed(12)

# Load data

data(usmacro)

# Run Model

fit <- bvar.sv.tvp(usmacro, p = 2)

##

##

##

##

##

##

##

[1]

[1]

[1]

[1]

[1]

[1]

[1]

"2015-11-26

"2015-11-26

"2015-11-26

"2015-11-26

"2015-11-26

"2015-11-26

"2015-11-26

09:46:35

09:47:22

09:48:59

09:50:36

09:52:14

09:53:51

09:55:28

--------

now

now

now

now

now

now

now

starting MCMC"

at iteration 5000"

at iteration 15000"

at iteration 25000"

at iteration 35000"

at iteration 45000"

at iteration 55000"

tml <- paste0(floor(time(usmacro)), "Q", (1 + 4*(time(usmacro) - floor(time(usmacro)))))

# Convenience functions for plotting

matplot2 <- function(x, y, ylim, ...){

matplot(x = x, y = y, ylim = ylim, type = "l", xlab = "", ylab = "",

lty = 1, lwd = 2, bty = "n", ...)

}

abline2 <- function(...){

abline(..., lty = 4, lwd = 0.3)

}

gp <- seq(1965, 2000, 5)

# Color palette, taken from http://www.cookbook-r.com/Graphs/Colors_%28ggplot2%29/

cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2",

"#D55E00", "#CC79A7")

cols1 <- cbPalette[c(2, 4, 2)]

cols2 <- cbPalette[c(2, 4, 6)]

# SD of inflation residual

# X axis

xax <- seq(1963.5, 2001.5, 0.25)

# Get posterior draws

aux <- seq(1, 3*153, 3)

x1 <- sqrt(fit$H.draws[1, aux, ])

x1 <- t(apply(x1, 1, function(z) c(mean(z), quantile(z, c(0.16, 0.84)))[c(2, 1, 3)]))

# Plot

matplot2(x = xax, y = x1, ylim = c(0, 0.8), col = cols1,

main = "Figure 9, panel (a)")

abline2(h = c(0.2, 0.4, 0.6), v = gp)

0.0

0.2

0.4

0.6

0.8

1970

1980

1990

2000

# SD of unemployment residual

# Get posterior draws

x2 <- sqrt(fit$H.draws[2, aux + 1, ])

x2 <- t(apply(x2, 1, function(z) c(mean(z), quantile(z, c(0.16, 0.84)))[c(2, 1, 3)]))

# Plot

matplot2(x = xax, y = x2, ylim = c(0, 1), col = cols1,

main = "Figure 9, panel (b)")

abline2(h = c(0.5, 1), v = gp)

0.0

0.2

0.4

0.6

0.8

1.0

1970

1980

1990

2000

# Get posterior draws

x3 <- sqrt(fit$H.draws[3, aux + 2, ])

x3 <- t(apply(x3, 1, function(z) c(mean(z), quantile(z, c(0.16, 0.84)))[c(2, 1, 3)]))

# Plot

matplot2(x = xax, y = x3, ylim = c(0, 5), col = cols1,

main = "Figure 9, panel (c)")

abline2(h = 1:4, v = gp)

1970

1980

1990

2000

# Dates to be considered

all_dts <- c("1975Q1", "1981Q3", "1996Q1")

# Loop over two response variables

# Inflation (rr = 1) and unemployment (rr = 2)

for (rr in 1:2){

tmp <- list()

for (dd in all_dts){

t <- which(tml == dd) - 42

t_ind <- which(all_dts == dd)

# Compute impulse responses

aux <- impulse.responses(fit, impulse.variable = 3,

response.variable = rr, t = t,

scenario = 3,

draw.plot = FALSE)$irf

tmp[[t_ind]] <- aux

}

# Make data for graph in top left panel of Figure 10, 11

gdat <- rbind(0, sapply(tmp, function(z) apply(as.matrix(z), 2, median)))

# Configure and print plot

if (rr == 1){

yb <- c(-0.2, 0.05)

} else {

yb <- c(-0.05, 0.15)

}

plot_title <- paste0("Figure ", 9 + rr, ", panel (a)")

matplot2(x = 0:20, y = gdat, ylim = yb, col = cols2, main = plot_title)

abline2(v = seq(5, 20, 5), h = seq(yb[1], yb[2], 0.05))

if (rr == 1){

legend_loc <- "bottomleft"

} else {

legend_loc <- "bottom"

}

legend(legend_loc, legend = all_dts, col = cols2, lty = 1, lwd = 2, bty = "n")

# Code for other panels in Figures 10, 11

# cc represent pairwise comparisons among system variables

for (cc in 1:3){

if (cc == 1){

comp <- 1:2

} else if (cc == 2){

comp <- c(1, 3)

} else {

comp <- c(2, 3)

}

# Summarize differences in Impulse Responses

aux <- t(apply(tmp[[comp[1]]] - tmp[[comp[2]]], 2,

function(z) quantile(z, c(0.16, 0.5, 0.84))))

# Configure and print plot

plot_title <- paste0("Figure ", 9 + rr, ", panel (", letters[2:4][cc], ")")

matplot2(x = 0:20, y = rbind(0, aux), ylim = c(-0.1, 0.1), col = cols1,

main = plot_title)

abline2(v = seq(5, 20, 5), h = seq(-0.1, 0.1, 0.05))

}

}

0.10

0.00

0.05

0.20

1975Q1

1981Q3

1996Q1

0

10

15

20

0.10

0.05

0.00

0.05

0.10

10

15

20

0.10

0.05

0.00

0.05

0.10

10

15

20

0.10

0.05

0.00

0.05

0.10

10

15

20

0.00

0.05

0.10

0.15

0.05

1975Q1

1981Q3

1996Q1

0

10

10

15

20

0.10

0.05

0.00

0.05

0.10

10

11

15

20

0.10

0.05

0.00

0.05

0.10

10

12

15

20

0.10

0.05

0.00

0.05

0.10

10

13

15

20

- ProgramsUploaded byDen Jensel Laroco Ares
- IT430 Assignment 3 CalculatorUploaded byImran
- LPinMatlab2012Uploaded byPreksha Pandey
- mysqllab.txtUploaded byAnonymous xkGlCCE4
- Pre-3AUploaded bySudip799
- StackUploaded bydurexko
- Lesson 11Uploaded byKhuleedShaikh
- Microarray time seriesUploaded byMohamed Mahmoud
- Cost Sheet DumpUploaded byHasan Shadab
- Non Dominated SortingUploaded bySourav Das
- F2L Feliks ZemdegsUploaded byNik Quaqua Quaresima
- Computer Notes - Data Structures - 31Uploaded byecomputernotes
- winter c++Uploaded byDhruv Varhney
- Ant Colony Optimization Aco for the Traveling Salesman Problem Tsp Using PartitioningUploaded byIJSTR Research Publication
- Visual VasicUploaded byNae Bogdan
- PresentationOM.pptxUploaded byGohil Hardik
- KNX Telegram DefinitionsUploaded byJose Rodriguez
- ch03.pdfUploaded byDivya Dave
- Código Macros Mover-objetos en Power PointUploaded byguerodiaz1971
- Programme Specification for CS 2012Uploaded byJohn Philip
- 4 - 2 - Resizing Arrays (956)Uploaded byeshwaar1
- SchedLgUUploaded byArween Sad
- Ant ColonyUploaded byFernando Larrainzar
- Report-664-2000Uploaded bysohail2006
- DFS Algorithm for GraphUploaded byMayank Chauhan
- SchedLgUUploaded byLuis Angel
- library_manifest.txtUploaded bytheo_31
- jwbn hackerrankUploaded byUrratul Aqyuni
- code to flowUploaded byash
- NeidfeldtBeard13-1Uploaded byKhalid Haider

- 2017bl04Uploaded byRene Barrera
- Cariera ProfesUploaded byLumi Luminita
- CatalogUploaded byRene Barrera
- 112701 Sample Paper R W PETUploaded byEduard Urgell
- 2017bl02Uploaded byRene Barrera
- unelte.pdfUploaded byRene Barrera
- gramatica limbii englezeUploaded byAnca Ank
- 2017bl05Uploaded byRene Barrera
- 2017bl03Uploaded byRene Barrera
- Buletin Lunar BNR 1 - 2017Uploaded byStudent Office
- 2017bl07Uploaded byRene Barrera
- 2017bl06Uploaded byRene Barrera
- Decizie Iccj Ril 22 2015 Sarbatori LegaleUploaded byRene Barrera
- 2017bl11Uploaded byRene Barrera
- untitled.pdfUploaded byRene Barrera
- r 20160510 GuvUploaded byRene Barrera
- 112701 Sample Paper R W PETUploaded byEduard Urgell
- a.pdfUploaded byRene Barrera
- a.pdfUploaded byRene Barrera
- a.pdfUploaded byRene Barrera
- a.pdfUploaded byRene Barrera
- Hot.257_2011-Norme Legea Pensiilor 2011Uploaded byIonescu Cosmin
- Spete.pdfUploaded byRene Barrera
- Spete.pdfUploaded byRene Barrera
- Spete.pdfUploaded byRene Barrera
- codul muncii 2011 + CMUNUploaded byMirela Paraschiv
- Pet January2011Uploaded byNoa Cruz Diaz
- 2017bl12Uploaded byRene Barrera
- art 9 C.I.MUploaded byBianca Ionela S
- Sistemul Unitar de Pensii PubliceUploaded byLEWWIS

- Precast_Arches_05.pdfUploaded byESTHER TEO
- AAAUploaded byVP
- linearlight-colormix-flex-and-linearlight-colormix-flex-protect---quick-installation-guide.pdfUploaded byeuqehtb
- Mendoza et al. 2010Uploaded byarmandosano
- Food Sample LabUploaded byNurulnameii
- IOM-MigrationinJamaica2010 FINAL 311012Uploaded byaldaine walker
- The.power.of.Play.in.a.high.Tech.worldUploaded byQE Test
- NASA Hubble Focus Our Amazing Solar SystemUploaded byrpguido
- Worksheet !2 - Equilibrium ReactionsUploaded byHenry Song
- IS 2705 notesUploaded byPhani Kumar
- MT8820C_radio Communication AnalyzerUploaded bypiller_huang
- Mathematics 10Uploaded byobhichak
- 3HAC16578-enkalibreringUploaded byArvydas Gaurilka
- BlogGuide050919Uploaded byapi-3755532
- Emotional Intelligence for Project Managers, May 2, 2014Uploaded bydevjeet
- Drug Induced Movement DisordersUploaded byLucas Phi
- Asus M@N GreenUploaded bymersed_15
- Form 5 Chapter 10 Linear ProgramingUploaded byJenn
- Are You Sure You Have a Strategy QUploaded byRahul Khosla
- Army Transformation a View From the u.s. Army War College Pub256Uploaded byscparco
- q and ansUploaded byParveen Mittal
- Leaflets LifeplusUploaded byrosrajen
- WT60 Spare PartsUploaded byimed
- Campus Center for Appropriate Technology Newsletter, Spring 1996Uploaded byTsirtsisGeorge
- MRI bowel double contrastUploaded bychavdarbuch
- w-250-isspecificationsheetsUploaded byapi-261294473
- Digital Video 10 It a EseUploaded byElenaTopirceanu
- Sales & Marketing ExecutiveUploaded bydavidbanig
- tspsc aee civil syllabusUploaded byapi-293926977
- WacUploaded bykriteesinha