Learn R Programming

scf (version 1.0.5)

scf_download: Download and Prepare SCF Microdata for Local Analysis

Description

Downloads SCF public-use microdata from official servers. For each year, this function retrieves five implicates, merges them with replicate weights and official summary variables, and saves them as .rds files ready for use with scf_load().

Usage

scf_download(years = seq(1989, 2022, 3), overwrite = FALSE, verbose = TRUE)

Value

These files are designed to be loaded using scf_load(), which wraps them into replicate-weighted designs.

Arguments

years

Integer vector of SCF years to download (e.g., c(2016, 2019)). Must be triennial from 1989 to 2022.

overwrite

Logical. If TRUE, re-download and overwrite existing .rds files. Default is FALSE.

verbose

Logical. If TRUE, display progress messages. Default is TRUE.

Implementation

This function downloads from official servers three types of files for each year:

  • five versions of the dataset (one per implicate), each stored as a separate data frame in a list

  • a table of replicate weights, and

  • a data table with official derivative variables

These tables are collected to a list and saved to an .rds format file in the working directory. By default, the function downloads all available years.

Details

The SCF employs multiply-imputed data sets to address unit-level missing data. Each household appears in one of five implicates. This function ensures all implicates are downloaded, merged, and prepared for downstream analysis using scf_load(), scf_design(), and the scf workflow.

References

U.S. Federal Reserve. Codebook for 2022 Survey of Consumer Finances. https://www.federalreserve.gov/econres/scfindex.htm

See Also

scf_load(), scf_design(), scf_update()

Examples

Run this code
if (FALSE) {
  # Download and prepare SCF data for 2022
  td <- tempfile("download_")
  dir.create(td)

  old <- getwd()
  setwd(td)
  scf_download(2022)

  # Load into a survey design object
  scf2022 <- scf_load(2022, data_directory = td)

  # Cleanup for package check
  unlink(td, recursive = TRUE, force = TRUE)
  setwd(old)
}

Run the code above in your browser using DataLab