# ------------------------------------------------------------------------------ # bch_baseline_plot.R # Plots for baseline model # Backus, Cooley, and Henriksen, "International Capital Flows" # Written by Espen Henriksen, April 2011 # ------------------------------------------------------------------------------ rm(list=ls()) setwd("c:/Documents and Settings/dbackus/My Documents/Userdata/Papers/BCH/model") load("bch_baseline_plot.Rdata") TAB <- rbind(NFAGDP) barplot(TAB, beside = TRUE,col=c("grey","blue","orange","darkblue","red","darkgreen"), ylab="NFA/GDP",ylim=c(-.6,1.2)) legend("topleft", legend = rownames(TAB),fill=c("grey","blue","orange","darkblue","red","darkgreen"),bty="n") dev.print(device = postscript,"nfaovergdp.eps",onefile = FALSE, horizontal = FALSE) dev.print(device = pdf,"nfaovergdp.pdf") barplot(NFA[1,1:7,3]/abs(NFA[1,6,3]),col="navy",ylab="NFA position, normalized by the U.S. position",ylim=c(-1,1)) dev.print(device = postscript,"nfaposition.eps",onefile = FALSE, horizontal = FALSE) dev.print(device = pdf,"nfaposition.pdf") tmp <- array(0, dim=c(nc,ny,2),dimnames=list(countries,years,c("Model", "IMF"))) for(i in 1:nc){ for(j in 1:ny){ tmp[i,j,1] <- NFA[2,i,j]/NFA[2,6,j] tmp[i,j,2] <- imfgdp[j,i]/imfgdp[j,6] } } relgdpcomp <- tmp rm(tmp,i,j) TAB <- rbind(t(relgdpcomp[1,,]),t(relgdpcomp[2,,]),t(relgdpcomp[3,,]),t(relgdpcomp[4,,]),t(relgdpcomp[5,,]),t(relgdpcomp[6,,]),t(relgdpcomp[7,,])) mp <- barplot(TAB, beside = TRUE, axisnames = FALSE,col=c("deepskyblue","indianred"),ylab="GDP relative to the U.S.",args.legend = list(x = "topleft")) legend("topleft",legend = c("Model","Data"),bty="n") mtext(1, at = mp, text = c("M", "D"),line = 0, cex = 0.40) at <- t(sapply(seq(1, nrow(TAB), by = 2), function(x) colMeans(mp[c(x, x+1), ]))) mtext(1, at = at, text = rep(countries, 6),line = 1, cex = 0.50) mtext(1, at = colMeans(mp), text=years, line = 2) dev.print(device=pdf,file="relgdpcomp.pdf") dev.copy2eps(device=postscript,file="relgdpcomp.eps",width=8,height=6) plot(rownames(NFAGDP),NFAGDP[,1],type="l",lwd=2,ylim = c(-.8,1.2),ylab = "NFA (% of GDP)",xlab = "") for(i in 2:nc){ lines(rownames(NFAGDP),NFAGDP[,i],lwd=2,col = c(i)) } legend("topleft",legend=countries,col=c(1:nc),lwd = 2,y.intersp=0.5,x.intersp=0.2, ncol=4, bty="n") dev.print(device=pdf,file="MBase_nfagdp.pdf") dev.copy2eps(device=postscript,file="Mbase_nfagdp.eps",width=8,height=6)