Skip to content

lorae/households-over-the-years

Repository files navigation

🏘️ Households Over the Years

How has household size and configuration changed in the last 125 years? We answer this question using publicly available American Community Survey and Decennial Census data, accessed via IPUMS, alongside the analytic tools available in the demographR package.

📊 Key Findings

The average American at the turn of the 20th century lived in a household with nearly 6 individuals. With some exceptions, that value has since been on the decline, with the rate of decrease in household size much slower in recent decades than during most of the 20th century. As of 2023, the average American lives in a household of 3.33 persons.

⚡ Quick Start

For experienced users who just want to get the project running right away. If you have trouble following these steps, please follow the Detailed Start guide below.

  1. Navigate to the directory where you want the project to be saved and clone both required repos side by side

    cd your/path/to/parent/directory
    git clone https://github.com/lorae/households-over-the-years households-over-the-years
    git clone https://github.com/lorae/demographr demographr
  2. Enter the main project

    cd households-over-the-years
  3. Copy the environment file and edit it with your own IPUMS API key

    cp example.Renviron .Renviron
    # (Windows PowerShell: Copy-Item example.Renviron .Renviron)
    # IMPORTANT: open .Renviron and replace "your_ipums_api_key" with your actual key
  4. Restore dependencies and run the analysis

    Open households-over-the-years.Rproj in your preferred IDE, then in the R console:

    renv::restore()
    source("run-all.R")

📎 Detailed Start

Detailed instructions for how to fully install and run this project code on your computer.

Part A: Clone the repo and configure the R project

These steps will allow you to install the code on your computer that runs this project and set up the environment so that it mimics the environment on which the code was developed.

  1. Clone the repo: Open a terminal on your computer. Navigate to the directory you would like to be the parent directory of the repo, then clone the repo.

    MacOS/Linux:

    cd your/path/to/parent/directory
    git clone https://github.com/lorae/households-over-the-years households-over-the-years

    Windows:

    cd your\path\to\parent\directory
    git clone https://github.com/lorae/households-over-the-years households-over-the-years
  2. Open the R project: Navigate into the directory, now located at your/path/to/parent/directory/households-over-the-years. Open households-over-the-years.Rproj using your preferred IDE for R. (We use R Studio.)

    Every subsequent time you work with the project code, you should always open the households-over-the-years.Rproj file at the beginning of your work session. This will avoid common issues with broken file paths or an incorrect working directory.

  3. Initialize R environment: Install all the dependencies (packages) needed to make the code run on your computer.

    First, ensure you have the package manager, renv, installed. Run the following in your R console:

    install.packages("renv") # Safe to run, even if you're not sure if you already have renv
    library("renv")

    Then restore the project:

    renv::restore()
  4. Clone the sibling repo, demographr: This project makes use of a bundle of functions that are unit-tested and generalized in a package called demographr. Clone this repo in the same parent directory where you cloned immigrant-households.

    🛑 Important: Do not clone this inside of the immigrant-households repo: instead, it should be a sibling: it should contained in the same folder structure as households-over-the-years.

    MacOS/Linux:

    cd your/path/to/parent/directory
    git clone https://github.com/lorae/demographr demographr

    Windows:

    cd your\path\to\parent\directory
    git clone https://github.com/lorae/demographr demographr

Part B: Configure API Access

The IPUMS Terms of Use precludes us from directly sharing the raw microdata extract, however, the data used in this analysis is freely available after setting up an IPUMS USA account, and we provide an automated script that writes the API call and downloads the exact data used in this analysis.

  1. Copy the file example.Renviron to a new file named .Renviron in the project root directory. You can do this manually or use the following terminal commands:

    MacOS/Linux:

    cp example.Renviron .Renviron

    Windows (use PowerShell):

    Copy-Item example.Renviron .Renviron
  2. Set up your IPUMS USA API key: If you don't already have one, set up a free account on IPUMS USA. Use the new account to login to the IPUMS API key webpage. Copy your API key from this webpage.

  3. Open .Renviron (‼️not example.Renviron!) and replace your_ipums_api_key with your actual key. Do not include quotation marks. R will automatically load .Renviron when you start a new session. This keeps your API key private and separate from the codebase.

    🛑 Important: .Renviron is listed in .gitignore, so it will not be tracked or uploaded to GitHub — but example.Renviron is tracked, so do not put your actual API key in the example file.

Part C: Run the analysis scripts

The code for this project is stored in the src folder:

  • scripts/: executable analysis scripts

  • utils/: accessory modules (functions), subject to unit tests

  1. Run all code by sourcing the run-all.R script in your R console:

    source("run-all.R")

📜 License

MIT License (see LICENSE file).

📚 Citation

This repository accompanies ongoing research on households and household size.

For now, please cite as:
Households Over the Years: Replication Code and Analysis. Maintained by Lorae Stojanovic and Peter Hepburn.
GitHub. https://github.com/lorae/households-over-the-years

About

How have the ways Americans configure themselves into households changed over the years? We use ML clustering algorithms to study common ways Americans cohabitate.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages