Skip to contents

Read downloaded and unzipped csv and txt files obtained from NHGIS.org, with US Census Bureau data from the American Community Survey (ACS).

Needs to be updated for 2022 formats, etc.

Usage

nhgis(
  base.path = getwd(),
  code.dir = file.path(base.path, "nhgiscode"),
  data.dir = file.path(base.path, "nhgisdata"),
  silent = FALSE,
  savefiles = FALSE
)

Arguments

base.path

Optional base path, default is getwd()

code.dir

Optional path where extra code is. Not used.

data.dir

Optional path where data files are stored and output could be saved. Default is nhgiscode folder under base.path

silent

Optional, FALSE by default, whether to print info about progress, filenames found, etc.

savefiles

Optional, FALSE by default, whether to save .RData and maybe csv files of output returned.

Value

Returns a named list, one element per summary level found (names are, e.g., 'us', 'states', etc.). Each summary level has a list of the following: data, contextfields, fields, tables, geolevel, years, dataset
For example:
summary(x[['us']]) Length Class Mode data 279 data.frame list contextfields 3 data.frame list fields 4 data.frame list tables 4 data.frame list geolevel 1 -none- character years 1 -none- character dataset 1 -none- character

Details

This was designed to read and parse csv and txt files obtained from NHGIS.org and already unzipped in a local folder. It only reads one set of files at a time, meaning the data and codebook files all have to be for the same set of ACS tables (a single NHGIS query) (but can be a separate data & codebook file pair for each spatial resolution like county, state, etc.) Obtaining NHGIS.org data requires an account at https://data2.nhgis.org/main, https://www.nhgis.org Data can be downloaded by selecting, for example,
tracts and block groups, all in US, acs2007-2011, and specifying the desired ACS Table(s).
Research using NHGIS data should cite it as:
Minnesota Population Center. National Historical Geographic Information System: Version 2.0. Minneapolis, MN: University of Minnesota 2011.

Documentation for NHGIS datasets is available here. Research using NHGIS data should cite it as: Steven Manson, Jonathan Schroeder, David Van Riper, Tracy Kugler, and Steven Ruggles. IPUMS National Historical Geographic Information System: Version 16.0 dataset. Minneapolis, MN: IPUMS. 2021. http://doi.org/10.18128/D050.V16.0 For policy briefs or articles in the popular press, we recommend that you cite the use of NHGIS data as follows: IPUMS NHGIS, University of Minnesota, www.nhgis.org

See also

nhgisread() used by this function. Also, for other ways to obtain ACS data see get.acs()

Examples

 
  if (FALSE) { # \dontrun{
  x <- nhgis(data.dir = '~/Desktop/nhgis0009_csv')
  # save state data as csv
  write.csv(x$states$data, file='statedata.csv', row.names = FALSE)
  # Which geolevels were found (and what years)?
  summary(x)
  t(cbind(sapply(x, function(y) y[c('geolevel', 'years')])))
  summary(x[['counties']])
  # Which Census Bureau tables were found?
  x[['states']]$tables
  # See the data for one State
  t(x[['states']]$data[1, ])
  # How many counties are in each State?
  dat <- x[['counties']]$data
  cbind(sort(table(dat$STATE)))
  # How many counties have population > 1 million, for each State?
  cbind(sort(table(dat$STATE[dat$B01001.001 > 1E6])))
  } # }