In R using define_extract_micro how to select a range of variables

Hello, I couldn’t really find anything by searching and I was wondering if I could get some help on some R code I am running. I am trying to create an extract that will only get the data from ACS 2022 5 year that includes “Michigan” and people age 16 to 24.

The issue I am running into is that I cannot figure out is how to make it so the age range is selected. This is my code:

mi_extract ← define_extract_micro(
collection = “usa”,
description = “USA extract for Michigan”,
samples = c(“us2022c”),
variables = list(
var_spec(“statefip”, case_selections = “26”),
var_spec(“age”, case_selections = “016”:“024”)
))

Is there a way to select the given age groups or is it something that I will have to do post extraction?

Thank you.

You can use a vector of character values in order to specify a range in case_selections without needing to list each individual value. For instance, to request cases 16-24 for AGE from IPUMS USA, you could specify your request as:

mi_extract <- define_extract_micro(
collection = "usa",
description = "USA extract for Michigan",
samples = "us2022c",
variables = list(
var_spec("STATEFIP", case_selections = "26"),
var_spec("AGE", case_selections = as.character(16:24)))
)