Example masterlist

NOT_CRAN <- identical(tolower(Sys.getenv("NOT_CRAN")), "true")
knitr::opts_chunk$set(purl = NOT_CRAN,
                                            comment = "#>")

The Census APIs have over 200 endpoints, covering dozens of different datasets.

library(censusapi)

To see a current table of every available endpoint, run listCensusApis:

apis <- listCensusApis()
View(apis)

Here is a list of examples for dozens of the Census's API endpoints. Read more about discovering an API's variable and geography options in Getting started with censusapi

American Community Survey

ACS Detailed Tables

Get median household income, with associated annotations and margin of error, for census tracts in Alaska.

acs_income <- getCensus(name = "acs/acs5",
    vintage = 2017, 
    vars = c("NAME", "B19013_001E", "B19013_001EA", "B19013_001M", "B19013_001MA"), 
    region = "tract:*",
    regionin = "state:02")
head(acs_income)

ACS Subject Tables

Get the percent of people without an internet subscription by income for the five counties of New York City, with associated margins of error:

acs_subject <- getCensus(name = "acs/acs1/subject",
    vintage = 2017, 
    vars = c("NAME", "S2801_C02_019E", "S2801_C02_019M",
                     "S2801_C02_023E", "S2801_C02_023M", 
                     "S2801_C02_027E", "S2801_C02_027M",
                     "S2801_C02_031E", "S2801_C02_031M"), 
    region = "county:005,047,061,081,085",
    regionin = "state:36")
head(acs_subject)

ACS Data Profile

acs_profile <- getCensus(name = "acs/acs1/profile",
    vintage = 2017, 
    vars = "group(DP05)", 
    region = "region:*")

ACS Comparison Profiles

Get the mean travel time to work (in minutes) for the past five years.

acs_comparison <- getCensus(name = "acs/acs1/cprofile",
    vintage = 2017, 
    vars = c("NAME", "CP03_2013_025E", "CP03_2014_025E", "CP03_2015_025E", "CP03_2016_025E", "CP03_2017_025E"), 
    region = "metropolitan statistical area/micropolitan statistical area:*")
head(acs_comparison)

ACS Migration Flows

American Community Survey Migration Flows documentation

flows <- getCensus(name = "acs/flows",
    vintage = 2016,
    vars = c("MOVEDIN", "MOVEDOUT", "FULL1_NAME", "FULL2_NAME", "GEOID2"),
    region = "county:001",
    regionin = "state:01")
head(flows)

American Community Survey Language Statistics

American Community Survey Language Statistics documentation

Get the number of people in New York state who speak each language.

languages <- getCensus(name = "language",
    vintage = 2013,
    vars = c("EST", "LAN", "LANLABEL"),
    region = "state:36")
head(languages)

Annual Survey of Entrepreneurs

Annual Survey of Entrepreneurs documentation

ase_csa <- getCensus(name = "ase/csa",
    vintage = 2014,
    vars = c("GEO_TTL", "NAICS2012", "NAICS2012_TTL", "EMPSZFI", "EMPSZFI_TTL", "FIRMPDEMP"),
    region = "us:*")
head(ase_csa)

ase_cscb <- getCensus(name = "ase/cscb",
    vintage = 2014,
    vars = c("GEO_TTL", "NAICS2012_TTL", "ASECB", "ASECB_TTL", "SPOUSES", "SPOUSES_TTL", "YEAR", 
                     "FIRMPDEMP", "FIRMPDEMP_PCT", "RCPPDEMP", "RCPPDEMP_F", "RCPPDEMP_PCT", 
                     "EMP", "EMP_PCT", "PAYANN", "PAYANN_PCT", "FIRMPDEMP_S", "FIRMPDEMP_PCT_S", 
                     "RCPPDEMP_S", "RCPPDEMP_PCT_S", "EMP_S", "EMP_PCT_S", "PAYANN_S", "PAYANN_PCT_S"),
    region = "us:*")
head(ase_cscb)

ase_cscbo <- getCensus(name = "ase/cscbo",
    vintage = 2014,
    vars = c("GEO_TTL", "NAICS2012_TTL", "ASECBO", "ASECBO_TTL", "ACQBUS", "ACQBUS_TTL", 
                     "YEAR", "OWNPDEMP", "OWNPDEMP_PCT", "OWNPDEMP_S", "OWNPDEMP_PCT_S"),
    region = "us:*")
head(ase_cscbo)

Annual Survey of Manufactures

Annual Survey of Manufactures documentation

asm_state <- getCensus(name = "timeseries/asm/state",
    vars = c("GEO_TTL", "NAICS_TTL", "EMP"),
    region = "state:*",
    time = 2016,
    naics = "31-33")
head(asm_state)

asm_product <- getCensus(name = "timeseries/asm/product",
    vars = c("PSCODE_TTL", "GEO_TTL", "PRODVAL"),
    region = "us:*",
    time = 2016,
    pscode = 311111)
head(asm_product)

Business Dynamics Statistics

Business Dynamics Statistics documentation

firms_states <- getCensus(name = "timeseries/bds/firms",
    vars = c("firms", "emp", "fage4"),
    region = "state:*",
    time = 2014)
head(firms_states)

firms_years <- getCensus(name = "timeseries/bds/firms",
    vars = c("firms", "emp"),
    region = "state:01",
    time = "from 1977 to 2014")
head(firms_years)

County Business Patterns and Nonemployer Statistics

County Business Patterns and Nonemployer Statistics documentation

County Business Patterns

County Business Patterns documentation

Get employment data for the construction industry.

cbp_2016 <- getCensus(name = "cbp",
 vintage = 2016,
 vars = c("GEO_TTL", "EMP", "ESTAB", "NAICS2012_TTL"),
 region = "state:*",
 naics2012 = 23)
 head(cbp_2016)

Get employment data by state for companies with more than 1,000 employees.

cbp_2008 <- getCensus(name = "cbp",
                                            vintage = 2008,
                                            vars = c("YEAR", "GEO_TTL", "EMPSZES_TTL", "EMP", "ESTAB", "PAYANN"),
                                            region = "state:*",
                                            EMPSZES = 260)
head(cbp_2008)

Zip Codes Business Patterns

Zip Codes Business Patterns documentation

zbp_2016 <- getCensus(name = "zbp",
 vintage = 2016,
 vars = c("GEO_TTL", "EMP"),
 region = "zipcode:90210")
head(zbp_2016)

Nonemployer statistics

Nonemployer statistics documentation

nonemp <- getCensus(name = "nonemp",
 vintage = 2016,
 vars = c("GEO_TTL", "NRCPTOT", "NAICS2012_TTL"),
 region = "state:*",
 naics2012 = 54)
head(nonemp)

Decennial Census

Decennial Census documentation Total population and housing units for metropolitan/micropolitan statistical areas in 2010.

data2010 <- getCensus(name = "dec/sf1",
    vintage = 2010,
    vars = c("NAME", "P001001", "H010001"), 
    region = "metropolitan statistical area/micropolitan statistical area:*")
head(data2010)

Get the urban/rural status group of variables (P2) by metropolitan/micropolitan statistical areas in 2010.

# Show variable metadata for the P2 group
group_p2 <- listCensusMetadata(name = "dec/sf1",
    vintage = 2010,
    type = "variables",
    group = "P2")

# Get the P2 variable group (URBAN AND RURAL)
data2010 <- getCensus(name = "dec/sf1",
    vintage = 2010,
    vars = "group(P2)", 
    region = "metropolitan statistical area/micropolitan statistical area:*")
head(data2010)

Get 2010 population by block group within a specific tract.

data2000 <- getCensus(name = "sf1",
    vintage = 2000,
    vars = "P001001", 
    region = "block:*",
    regionin = "state:36+county:027+tract:010000")
head(data2000)

Decennial Census Surname Files

Decennial Census Surname documentation

Get counts of the top 25 most popular surnames and share of each by race.

top_surnames <- getCensus(name = "surname",
    vintage = 2010,
    vars = c("NAME", "COUNT", "PROP100K", "PCTWHITE", "PCTBLACK", "PCTAIAN", "PCTAPI", "PCTHISPANIC", "PCT2PRACE"),
    RANK = "1:25")
head(top_surnames)

Economic Census

Economic Census documentation

ewks_2012 <- getCensus(name = "ewks",
    vintage = 2012,
    vars = c("EMP", "OPTAX", "GEOTYPE"),
    region = "state:*",
    naics2012 = 54)
head(ewks_2012)
ewks_2007 <- getCensus(name = "ewks",
    vintage = 2007,
    vars = c("EMP", "OPTAX", "GEOTYPE"),
    region = "state:*",
    naics2007 = 54)
head(ewks_2007)

Economic Indicators

Economic Indicators documentation

eits <- getCensus(name = "timeseries/eits/resconst",
    vars = c("cell_value", "data_type_code", "time_slot_id", "error_data", "category_code", "seasonally_adj"),
    region = "us:*",
    time = "from 2004-05 to 2012-12")
head(eits)

Health Insurance Statistics

Health Insurance Statistics documentation

Get the uninsured rate by income group in Alabama for a single year.

sahie <- getCensus(name = "timeseries/healthins/sahie",
    vars = c("NAME", "IPRCAT", "IPR_DESC", "PCTUI_PT"),
    region = "state:01",
    time = 2017)
head(sahie)

Get the uninsured rate in Alabama for multiple years.

sahie_annual <- getCensus(name = "timeseries/healthins/sahie",
    vars = c("NAME", "PCTUI_PT"),
    region = "state:01",
    time = "from 2006 to 2017")
sahie_annual

Get the uninsured rate for non-elderly adults with incomes of 138 to 400% of the poverty line, by race and state.

sahie_nonelderly <- getCensus(name = "timeseries/healthins/sahie",
    vars = c("NAME", "IPR_DESC", "PCTUI_PT", "AGE_DESC", "RACECAT", "RACE_DESC"), 
    region = "state:*", 
    time = 2017,
    IPRCAT = 5,
    AGECAT = 1)
head(sahie_nonelderly)

International Data Base

International Data Base documentation

Get Census Bureau projections of 2020 populations and life expectancy at birth by country.

intl_pop <- getCensus(name = "timeseries/idb/5year",
    vars = c("NAME", "FIPS", "POP", "E0"),
    time = 2020)
head(intl_pop)

Get predictions of population by age in 2050 for Norway for ages 10-18. https://api.census.gov/data/timeseries/idb/1year?get=AREA_KM2,NAME,AGE,POP&FIPS=NO&time=2050

norway_pop <- getCensus(name = "timeseries/idb/1year",
    vars = c("NAME", "POP"),
    time = 2050,
    FIPS = "NO",
    AGE = "10:18")
head(norway_pop)

International Trade

International Trade documentation

Note: The international trade datasets are buggy and frequently give the general error message of "There was an error while running your query. We've logged the error and we'll correct it ASAP. Sorry for the inconvenience." This error message comes from the U.S. Census Bureau. If you run in to repeated issues or inconsistencies, contact the Census Bureau for help or consider using a bulk data download instead.

Get the general imports value and imports for consumption value for all end-use codes and all countries for January 2018.

imports <- getCensus(name = "timeseries/intltrade/imports/enduse",
    vars = c("CTY_CODE", "CTY_NAME", "I_ENDUSE", "I_ENDUSE_LDESC", "GEN_VAL_MO", "CON_VAL_MO"),
    time = "2018-01")
head(imports)

Population Estimates and Projections

Population Estimates and Projections documentation

Population Estimates

Population Estimates documentation

popest <- getCensus(name = "pep/population",
    vintage = 2018,
    vars = c("GEONAME", "POP", "DATE_DESC"),
    region = "state:*")
head(popest)
popest_housing <- getCensus(name = "pep/housing",
    vintage = 2017,
    vars = c("DATE", "DATE_DESC", "GEONAME", "HUEST"),
    region = "county:195",
    regionin = "state:2")
head(popest_housing)

Population Projections

Population Projections documentation

popproj <- getCensus(name = "pep/projpop",
    vintage = 2014,
    vars = c("YEAR", "POP", "AGE"),
    region = "us:1")
head(popproj)

Poverty Statistics

Poverty Statistics documentation

Current Population Survey Poverty Statistics

Get national poverty rates by race for the past 50 years.

poverty <- getCensus(name = "timeseries/poverty/histpov2",
    vars = c("RACE", "PCTPOV"),
    region = "us:*",
    time = "from 1967 to 2017")
head(poverty)

Small Area Income and Poverty Estimates

Get poverty rate for children and overall for a single year.

saipe <- getCensus(name = "timeseries/poverty/saipe",
    vars = c("NAME", "SAEPOVRT0_17_PT", "SAEPOVRTALL_PT"),
    region = "state:*",
    time = 2017)
head(saipe)

Get the poverty rate for children and overall in a single county over time.

saipe_years <- getCensus(name = "timeseries/poverty/saipe",
    vars = c("NAME", "SAEPOVRT0_17_PT", "SAEPOVRTALL_PT"),
    region = "county:001",
    regionin = "state:12",
    time = "from 2000 to 2017")
head(saipe_years)

SAIPE School Districts

Get the number (SAEPOV5_17V_PT) and rate (SAEPOVRAT5_17RV_PT) of children ages 5-17 living in poverty for unified school districts in Massachusetts.

saipe_schools <- getCensus(name = "timeseries/poverty/saipe/schdist",
    vars = c("SD_NAME", "SAEPOV5_17V_PT", "SAEPOVRAT5_17RV_PT"),
    region = "school district (unified):*",
    regionin = "state:25",
    time = 2017)
head(saipe_schools)

Quarterly Workforce Indicators

Quarterly Workforce Indicators documentation

The allow both simple calls and very specfic ones. Make sure to read the documentation closely. Here's a simple call that gets employment data by county.

qwi_counties <- getCensus(name = "timeseries/qwi/sa",
    vars = c("Emp", "EarnBeg"),
    region = "county:*",
    regionin = "state:01",
    time = "2016-Q1")
head(qwi_counties)

Employment data over time for a single state.

qwi_time <- getCensus(name = "timeseries/qwi/sa",
    vars = c("Emp", "EarnBeg"),
    region = "state:01",
    time = "from 2007 to 2017")
head(qwi_time)

Here's a much more specific call. Read the Census Bureau's documentation closely to see all of the options allowed by the QWI APIs.

qwi <- getCensus(name = "timeseries/qwi/sa",
    region = "state:02",
    vars = c("Emp", "sex"),
    year = 2012,
    quarter = 1,
    agegrp = "A07",
    ownercode = "A05",
    firmsize = 1,
    seasonadj = "U",
    industry = 21)
qwi

Survey of Business Owners

Survey of Business Owners documentation

sbo <- getCensus(name = "sbo",
    vintage = 2012,
    vars = c("GEO_TTL", "RCPSZFI", "RCPSZFI_TTL", "FIRMPDEMP"),
    region = "state:*")
head(sbo)

sbo_groups <- getCensus(name = "sbo",
    vintage = 2012,
    vars = c("GEO_TTL", "RACE_GROUP", "RACE_GROUP_TTL", "FIRMPDEMP"),
    region = "county:*",
    regionin = "state:09")
head(sbo_groups)

The Planning Database

The Planning Database documentation Get population and 2010 Census mail return rates for block groups in Autauga County, AL.

pdb <- getCensus(name = "pdb/blockgroup",
    vintage = 2018,
    vars = c("GIDBG", "County_name", "State_name", "Tot_Population_CEN_2010", "Mail_Return_Rate_CEN_2010"),
    region = "block group:*",
    regionin = "state:01+county:001")
head(pdb)

Disclaimer

This product uses the Census Bureau Data API but is not endorsed or certified by the Census Bureau.



Try the censusapi package in your browser

Any scripts or data that you put into this service are public.

censusapi documentation built on May 2, 2019, 9:39 a.m.