add_to_extract_micro: Add values to an existing extract definition for an IPUMS...

add_to_extract_microR Documentation

Add values to an existing extract definition for an IPUMS microdata collection

Description

[Experimental]

Add new values or replace existing values in an IPUMS microdata extract definition. All fields are optional, and if omitted, will be unchanged. Supplying a value for fields that take a single value, such as description and data_format, will replace the existing value with the supplied value.

This function is marked as experimental because it is typically not the best option for maintaining reproducible extract definitions and may be retired in the future. For reproducibility, users should strive to build extract definitions with define_extract_*() functions.

If you have a complicated extract definition to revise, but do not have the original extract definition code that created it, we suggest that you save the revised extract as a JSON file with save_extract_as_json(). This will create a stable version of the extract definition that can be used in the future as needed.

To remove existing values from an IPUMS microdata extract definition, use remove_from_extract().

Learn more about the IPUMS API in vignette("ipums-api").

Usage

## S3 method for class 'micro_extract'
add_to_extract(
  extract,
  description = NULL,
  samples = NULL,
  variables = NULL,
  data_format = NULL,
  data_structure = NULL,
  rectangular_on = NULL,
  case_select_who = NULL,
  data_quality_flags = NULL,
  ...
)

Arguments

extract

An ipums_extract object.

description

Description of the extract.

samples

Vector of samples to include in the extract request. Use get_sample_info() to identify sample IDs for a given collection.

variables

Character vector of variable names or a list of var_spec objects created by var_spec() containing specifications for all variables to include in the extract.

If a variable already exists in the extract, its specifications will be added to those that already exist for that variable.

data_format

Format for the output extract data file. Either "fixed_width" or "csv".

Note that while "stata", "spss", or "sas9" are also accepted, these file formats are not supported by ipumsr data-reading functions.

data_structure

Data structure for the output extract data.

  • "rectangular" provides person records with all requested household information attached to respective household members.

  • "hierarchical" provides household records followed by person records.

Defaults to "rectangular".

rectangular_on

If data_structure is "rectangular", records on which to rectangularize. Currently only "P" (person records) is supported.

Defaults to "P" if data_structure is "rectangular" and NULL otherwise.

case_select_who

Indication of how to interpret any case selections included for variables in the extract definition.

  • "individuals" includes records for all individuals who match the specified case selections.

  • "households" includes records for all members of each household that contains an individual who matches the specified case selections.

Defaults to "individuals". Use var_spec() to add case selections for specific variables.

data_quality_flags

Set to TRUE to include data quality flags for all applicable variables in the extract definition. This will override the data_quality_flags specification for individual variables in the definition.

Use var_spec() to add data quality flags for specific variables.

...

Ignored

Details

If the supplied extract definition comes from a previously submitted extract request, this function will reset the definition to an unsubmitted state.

To modify variable-specific parameters for variables that already exist in the extract, create a new variable specification with var_spec().

Value

A modified micro_extract object

See Also

remove_from_extract() to remove values from an extract definition.

submit_extract() and download_extract() to submit and process an extract request.

define_extract_*() to create a new extract definition from scratch

Examples

extract <- define_extract_usa(
  description = "2013 ACS Data",
  samples = "us2013a",
  variables = c("SEX", "AGE", "YEAR")
)

# Add a single sample
add_to_extract(extract, samples = "us2014a")

# Add samples and variables
extract2 <- add_to_extract(
  extract,
  samples = "us2014a",
  variables = c("MARST", "BIRTHYR")
)

# Modify specifications for variables in the extract by using `var_spec()`
# with the existing variable name:
add_to_extract(
  extract,
  samples = "us2014a",
  variables = var_spec("SEX", case_selections = "2")
)

# You can make multiple modifications or additions by providing a list
# of `var_spec()` objects:
add_to_extract(
  extract,
  samples = "us2014a",
  variables = list(
    var_spec("RACE", attached_characteristics = "mother"),
    var_spec("SEX", case_selections = "2"),
    var_spec("RELATE")
  )
)

# Values that only take a single value are replaced
add_to_extract(extract, description = "New description")$description

ipumsr documentation built on Oct. 20, 2023, 5:10 p.m.