Last data update: 2014.03.03

R: Read a National Income and Product Accounts data table
readNIPAR Documentation

Read a National Income and Product Accounts data table

Description

Read multiple files with data in rows using read.transpose and combine the initial columns.

Usage

readNIPA(files, sep.footnote='/', ...)

Arguments

files

A character vector of names of files from which the data are to be read using read.transpose.

sep.footnote

a single character to identify footnote references in the variable names in some but not all of files.

...

optional arguments for read.transpose

Details

This is written first and foremost to facilitate updating USFinanceIndustry from Table 6.16: Income and employment by industry in the National Income and Product Account tables published by the Bureau of Economic Analysis of the United States Department of Commerce. As of February 2013, this table can be obtained from http://www.bea.gov: Under "U.S. Economic Accounts", first select "Corporate Profits" under "National". Then next to "Interactive Tables", select, "National Income and Product Accounts Tables". From there, select "Begin using the data...". Under "Section 6 - income and employment by industry", select each of the tables starting "Table 6.16". As of February 2013, there were 4 such tables available: Table 6.16A, 6.16B, 6.16C and 6.16D. Each of the last three are available in annual and quarterly summaries. The USFinanceIndustry data combined the first 4 rows of the 4 annual summary tables.

This is available in 4 separate files, which must be downloaded and combined using readNIPA. The first three of these are historical data and are rarely revised. For convenience and for testing, they are provided in the demoFiles subdirectory of this Ecdat package.

It has not been tested on other data but should work for annual data with a sufficiently similar structure.

The algorithm proceeds as follows:

1. Data <- lapply(files, read.transpose)

2. Is Data a list of numeric matrices? If no, print an error.

3. cbind common initial variables, averaging overlapping years, reporting percent difference

4. attributes: stats from files and overlap. Stats include the first and last year and the last revision date for each file, plus the number of years overlap with the previous file and the relative change in the common files kept between those two files.

Value

a matrix of the common variables

Author(s)

Spencer Graves

References

United States Department of Commerce Bureau of Economic Analysis National Income and Product Account tables

See Also

read.table readLines strsplit

Examples

#  Find demoFiles/*.csv
demoDir <- system.file('demoFiles', package='Ecdat')
(demoCsv <- dir(demoDir, pattern='csv$', full.names=TRUE))

nipa6.16 <- readNIPA(demoCsv)
str(nipa6.16)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Ecfun)

Attaching package: 'Ecfun'

The following object is masked from 'package:base':

    sign

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Ecfun/readNIPA.Rd_%03d_medium.png", width=480, height=480)
> ### Name: readNIPA
> ### Title: Read a National Income and Product Accounts data table
> ### Aliases: readNIPA
> ### Keywords: IO
> 
> ### ** Examples
> 
> #  Find demoFiles/*.csv
> demoDir <- system.file('demoFiles', package='Ecdat')
> (demoCsv <- dir(demoDir, pattern='csv$', full.names=TRUE))
[1] "/home/ddbj/local/lib64/R/library/Ecdat/demoFiles/NIPA6.16A20090820.csv"
[2] "/home/ddbj/local/lib64/R/library/Ecdat/demoFiles/NIPA6.16B20080817.csv"
[3] "/home/ddbj/local/lib64/R/library/Ecdat/demoFiles/NIPA6.16C20080817.csv"
[4] "/home/ddbj/local/lib64/R/library/Ecdat/demoFiles/NIPA6.16D20130130.csv"
> 
> nipa6.16 <- readNIPA(demoCsv)
> str(nipa6.16)
 num [1:84, 1:6] 1929 1930 1931 1932 1933 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:84] "" "" "" "" ...
  ..$ : chr [1:6] "240" "    Corporate profits with inventory valuation and capital consumption adjustments" "Domestic industries" "  Financial" ...
 - attr(*, "headers")= chr [1:4] "Table 6.16D. Corporate Profits by Industry" "[Billions of dollars] " "Bureau of Economic Analysis " "Last Revised on: January 30, 2013 - Next Release Date February 28, 2013"
 - attr(*, "footers")= chr [1:7] "Legend / Footnotes:" "1. Consists of finance and insurance and bank and other holding companies." "2. Consists of credit intermediation and related activities; securities, commodity contracts, and other financial investments a"| __truncated__ "3. Consists of wood products; nonmetallic mineral products; primary metals; other transportation equipment; furniture and relat"| __truncated__ ...
 - attr(*, "summary")='data.frame':	4 obs. of  8 variables:
  ..$ headers      : int [1:4] 4 4 4 4
  ..$ footers      : int [1:4] 2 2 2 7
  ..$ data         : int [1:4] 19 35 35 34
  ..$ yearFirst    : num [1:4] 1929 1948 1987 1998
  ..$ yearLast     : num [1:4] 1947 1987 2000 2012
  ..$ yearsOverlap : num [1:4] NA 0 1 3
  ..$ lastRevision : Date[1:4], format: "2009-08-20" "2009-08-17" ...
  ..$ rmsDevOverlap: num [1:4] NA NA 0 0.00604
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>