# ------------------------------------------------------------------------------ # US_nw_gdp_Oct10.R # Plots US HH net worth and consumption over time # Reads in FOF data directly from Fed website and NIPA data from BEA website # Written by Espen Henriksen, September 2010 # Adapted (poorly) by Dave Backus # ------------------------------------------------------------------------------ setwd("c:/Documents and Settings/dbackus/My Documents/Userdata/Papers/BCH/data") # 1. BEA data # ------------------------------------------------------------------------------ # Download Table 1.1.5 Gross Domestic Product from BEA and assign it to a data frame called "beatbl115" beatbl115 <- read.csv("http://www.bea.gov/national/nipaweb/csv/NIPATable.csv?FirstYear=1947&TableName=5&LastYear=2010&ViewSeries=NO&freq=Qtr&3Place=N&Request3Place=N",skip=5,sep=",") # Assign row names to the data set. dimnames(beatbl115)[[1]] <- paste("L", beatbl115[,1],": ", sub("^ +", "", beatbl115[,2]), sep = "") # Delete redudant columns 1 and 2 beatbl115[,2] <- NULL beatbl115[,1] <- NULL # Transpose data beatbl115 <- t(beatbl115) # Format the data set as a time-series data set with quarterly data starting in 1947 beatbl115 <- ts(beatbl115, start=1947, frequency=4) # 2. FOF data # ------------------------------------------------------------------------------ # Download "Table B.100 Balance Sheet of Households and Nonprofit Organizations" from the Federal Reserve Flow of Funds webpage download.file(url="http://www.federalreserve.gov/releases/z1/current/Disk/btabs.zip",destfile="btabs.zip",method="auto",quiet=TRUE) btab100d <- read.csv(unzip(zipfile="btabs.zip",files="btab100d.prn",list=FALSE),header=TRUE,sep=" ") btab100d <- ts(btab100d,start=1952, frequency=4) # FL152090005.Q is Line 42 "Net worth" # FL155035005.Q is Line 3 "Real estate assets" # FL155012605.Q is Line 43 "Replacement-cost value of structures: Residential" # FL155012605.Q is Line 46 "Replacement-cost value of structures: Nonresidential (nonprofit)" # FL153064105.Q is Line 24 "Financial assets: Corporate equities" # FL153064105.Q is Line 25 "Financial assets: Mutual fund shares" cy <- beatbl115[,2]/beatbl115[,1] nwy <- btab100d[,"FL152090005.Q"]/beatbl115[,1] hmvy <- btab100d[,"FL155035005.Q"]/beatbl115[,1] hrcy <- (btab100d[,"FL155012605.Q"]+btab100d[,"FL165013665.Q"])/beatbl115[,1] eqy <- (btab100d[,"FL153064105.Q"]+btab100d[,"FL153064205.Q"])/beatbl115[,1] nwplot <- cbind(nwy,hmvy,hrcy,eqy) dimnames(nwplot)[[2]] <- c("net worth","real estate at market","real estate at cost","equity") #rm(list=c("eqy","hmvy","hrcy","nwy")) ts.plot(nwplot,ylim=c(0,4.8),gpars=list(xlab="Year",ylab="Ratio to GDP",lwd=2.0,lty=c(1:4),col=c(1:4))) legend("topleft",legend=colnames(nwplot),cex=0.75,lwd=2.0,lty=c(1:4),col=c(1:4)) dev.print(device=postscript,"nwgdpratio.eps",onefile=FALSE,horizontal=FALSE) #dev.print(device=pdf,"nwgdpratio.pdf") #rm(nwplot) cyplot <- cbind(cy) dimnames(nwplot)[[2]] <- c("consumption") ts.plot(cyplot,ylim=c(0.5,0.8),gpars=list(xlab="Year",ylab="Ratio to GDP",lwd=2.0,lty=c(1:1),col=c(1:1))) legend("topleft",legend = colnames(cyplot),cex=0.75,lwd=2.0,lty=c(1:1),col=c(1:1)) dev.print(device=postscript, "cyratio.eps",onefile=FALSE, horizontal=FALSE) #dev.print(device=pdf, "cyratio.pdf")