Census ACS data pull and fixed effects models for Utah housing research
Project description
utah-housing
Census ACS 5-year data fetcher and fixed effects models for Utah housing research.
Setup
pip install -e ".[dev]"
export CENSUS_API_KEY=your_key_here # https://api.census.gov/data/key_signup.html
Usage
Pull data
from utah_housing import fetch_all_years
df = fetch_all_years(years=range(2009, 2024))
df.to_csv("utah_housing_2009_2023.csv", index=False)
Pull a single year:
from utah_housing import fetch_year
df_2022 = fetch_year(2022)
Run models
import pandas as pd
from utah_housing import run_model
df = pd.read_csv("utah_housing_2009_2023.csv")
results, coefs = run_model(df)
coefs.to_csv("results.csv")
Run diagnostics
from utah_housing.models import run_diagnostics
from utah_housing import PREDICTORS
run_diagnostics(df, PREDICTORS)
Model Overview
We built a two-way fixed effects (or fixed panel) regression model to identify within-tract drivers of ownership costs. We initially wanted to use a simple multiple linear regression model, but found that we were explaining almost none of the variance in our data. A fixed effects model helps to remedy the inevitable unknown elements of variance in such an economic model, as it holds certain elements constant to account for inherent variance.
Our model controls for tract-level fixed effects, meaning time-invariant characteristics of a neighborhood like location and county $\times$ year fixed effects, which account for unknown variables like employer expansion and COVID-era impacts.
The model is as follows:
$$ y_{it} = \beta X_{it} + \alpha_i + \lambda_{c(i), t} + u_{i,t} $$
where $i =$ tract (Census GEOID), $t =$ year, and $c(i) =$ county of tract $i$.
$\alpha_i$ stands for tract fixed effect, which controls for anything constant within a tract over time, like location desirability, zoning baseline, and neighborhood quality. In other words, $\alpha$ lets us compare a tract to itself over time.
$\lambda_{c(i), t}$ stands for the county $\times$ year fixed effect, controlling for anything affecting a county in a specific year; things like local economic shocks (ex: big employer entering or leaving), policy changes, or impacts from COVID. In other words, $\lambda_{c(i), t}$ allows us to remove shared shocks across nearby areas at the same time.
Outcome: median_owner_costs_with_mortgage
Predictors:
pct_sf_renter_occupied— share of single-family homes that are renter-occupied (investor proxy)median_household_income— demand-side incomeowner_renter_income_gap— income stratification signalpct_vacant— market slackpop_in_occupied_total- population demand pressure
Data tables pulled
| Table | Description |
|---|---|
| B25024 | Units in structure |
| B25001 | Total housing units |
| B25002 | Occupancy status |
| B25003 | Tenure (owner vs. renter) |
| B25008 | Population in occupied housing by tenure |
| B25119 | Median household income by tenure |
| B25032 | Units in structure by tenure |
| B25088 | Median monthly owner costs |
| B19013 | Median household income |
Package layout
utah_housing/
├── __init__.py # public API
├── variables.py # all ACS variable lists, rename map, model variable sets
├── fetch.py # Census API fetcher
└── models.py # fixed effects models + diagnostics
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file utah_housing-0.1.1.tar.gz.
File metadata
- Download URL: utah_housing-0.1.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffa4ab1e00e13c395a8bc02e8e4db921f17e194e18916f70693f91e56db0aaa4
|
|
| MD5 |
543076de22614bbe40224e73f507cf54
|
|
| BLAKE2b-256 |
175075744b6fbbea797c8b0faaeb323d5be43cf07a7bff835f61f564d4ef0001
|
File details
Details for the file utah_housing-0.1.1-py3-none-any.whl.
File metadata
- Download URL: utah_housing-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbf265a83d77e1fd30bde5f3bb68ed2477540fbd05e75511c3cc5d7e09e4159b
|
|
| MD5 |
cccb44ae579871e122b02151bfbf551c
|
|
| BLAKE2b-256 |
2828b701db2976e1c3d8136744dd6b0e8ef6afbfbc1895cb6c3ae1a48c9a0baa
|