Source and metrics
Dimensions
To first get data from the Census Data API we have to gather these three dimensions.
- A source - what survey, and year do we want (e.g., ACS 2015 5-year estimate)
- A metric - what column we want to get the data for (e.g. population density)
- A geographic entity - (e.g state, county, census tract, census block)
The dimensions are then put as the different keys in the following object that is passed into CitySDK.
{
"sourcePath" : ["acs","acs1"], // source (survey, ACS 1-year estimate)
"vintage" : 2017, // source (year, 2017)
"values" : ["B00001_001E"], // metric (column for population count)
"geoHierarchy" : { // geographic entity (grouped by state)
"state" : "*"
}
}
The query will return the population count from ACS 2017 1-year estimate for all states.
Each dataset provides information for different topics, years, and at different levels of geography (national, state, county, block levels).
We will focus on the the American Community Survey (ACS) because of its wide variarty of population questions and frequent surveys.
You can also discover sources and metrics using the search feature in data.census.gov. If you need help trying to find a specific data set see the Community Page, we have helpful a community that will be happy to assist you.
Example
For the first example we will get the population of the all the States. At data.census.gov click on the Population under the Subjects heading on the main page. You can see the various tables that have population information, select the first one “Total Population in United States”
It will bring you to this window where you can look at the table in detail. Take a note of the following.
- Survey/Program: ACS
- Year: 2017
- Estimate: 1-year
- TableID: DP05
This will help you find the specific column ids needed for the query. For this example we will get the total population, male and female population columns.
1.Locate the Source on https://www.census.gov/data/developers/data-sets.html , using the Survey/Program ID, Year, and Estimate.
2.Select the year 2017
3.Select the specific profile, which is the prefix of the table id (DP). Note each profile has different prefixes look at the example or you can reference Notes on ACS API Variable Formats.
4.Click “html” for the 2017 ACS DAta Profiles Variables. Then find columns by searching the page (Ctrl + F) for your Tableid (DP05)
We found them!! Now copy the column names (DP05_0001E, DP05_0002E, DP05_0003E) and the url.
Constructing the Query
Following the template of a query we can fill in the following.
{
"sourcePath" : [""] // source (survey)
"vintage" : // source (year)
"values" : [], // metric (columns)
"geoHierarchy" : { // geographic entity (grouped by state)
"state" : "*"
}
}
We can find sourcePath and vintage by breaking down the url. The sourcePath is an array of the path.
https://api.census.gov/data/2017/acs/acs1/profile/variables.html
{
"sourcePath" : ["acs","acs1","profile"], // source (survey, ACS 1-year profile estimate)
"vintage" : 2017, // source (year, 2017)
}
Add you the column names in array, add “NAME” column too
{
"sourcePath" : ["acs","acs1","profile"],
"vintage" : 2017,
"values" : ["NAME","DP05_0001E","DP05_0002E", "DP05_0003E"], // metric (column for total count, male, and female popluation)
}
after your query is done, you will get this.
{
"sourcePath" : ["acs","acs1","profile"], // source (survey, ACS 1-year profile estimate)
"vintage" : 2017, // source (year, 2017)
"values" : ["NAME","DP05_0001E","DP05_0002E", "DP05_0003E"], // metric (column for total count, male, and female popluation)
"geoHierarchy" : { // geographic entity (grouped by state)
"state" : "*"
}
}
//result
[{
"NAME": "Alabama",
"DP05_0001E": 4874747,
"DP05_0002E": 2359896,
"DP05_0003E": 2514851,
"state": "01"
},
{
"NAME": "Alaska",
"DP05_0001E": 739795,
"DP05_0002E": 385776,
"DP05_0003E": 354019,
"state": "02"
},
...
}]
Additional Example
For the additional example, we will look at the Total households with one or more computing devices.
1.Search “computer” at data.census.gov, and take note of the program and table details.
- Survey/Program: ACS
- Year: 2017
- Estimate: 1-year
- TableID: S2801
- Locate the dataset, in this case it is a subject profile.
- Column Names: “S2801_C01_001E”,”S2801_C01_002E”
- URL: https://api.census.gov/data/2017/acs/acs1/subject/variables.html
Constructing the Query
{
"sourcePath" : ["acs","acs1","subject"], // source (survey, ACS 1-year subject estimate)
"vintage" : 2017, // source (year, 2017)
"values" : ["NAME","S2801_C01_001E","S2801_C01_002E" ], // metric (column for total households, one or more types of computing devices)
"geoHierarchy" : { // geographic entity (grouped by state)
"state" : "*"
}
}
//result
[{
"NAME": "Alabama",
"S2801_C01_001E": 1841665,
"S2801_C01_002E": 1585085,
"state": "01"
},
{
"NAME": "Alaska",
"S2801_C01_001E": 250741,
"S2801_C01_002E": 236300,
"state": "02"
},
...
}]