Get IPUMS metadata information about variables loaded into R. Will try to read the metadata from the loaded datasets, but it is more reliable to load the DDI into a separate object and use it instead.
ipums_var_info(object, vars = NULL) ipums_var_desc(object, var = NULL) ipums_var_label(object, var = NULL) ipums_val_labels(object, var = NULL)
object | A DDI object (loaded with |
---|---|
vars | dplyr |
var | select-style notation for a single variable
Note that many R functions drop attributes that provide this information.
In order to make sure that they are available, it is best to keep a copy of the
separate from the data your are manipulating using |
ipums_var_info
returns a tbl_df
data frame with variable information, and
the other functions return a length 1 character vector.
ddi <- read_ipums_ddi(ipums_example("cps_00006.xml")) ipums_var_info(ddi) #> # A tibble: 8 x 10 #> var_name var_label var_desc val_labels code_instr start end imp_decim #> <chr> <chr> <chr> <list> <chr> <dbl> <dbl> <dbl> #> 1 YEAR Survey ye~ "YEAR repo~ <tibble [0~ "\nYEAR is ~ 1 4 0 #> 2 SERIAL Household~ "SERIAL is~ <tibble [0~ "\nSERIAL i~ 5 9 0 #> 3 HWTSUPP Household~ "HWTSUPP i~ <tibble [0~ "\nHWTSUPP ~ 10 19 4 #> 4 STATEFIP State (FI~ "STATEFIP ~ <tibble [7~ NA 20 21 0 #> 5 MONTH Month "MONTH ind~ <tibble [1~ NA 22 23 0 #> 6 PERNUM Person nu~ "PERNUM nu~ <tibble [0~ "\nPERNUM i~ 24 25 0 #> 7 WTSUPP Supplemen~ "WTSUPP is~ <tibble [0~ "\nWTSUPP i~ 26 35 4 #> 8 INCTOT Total per~ "INCTOT in~ <tibble [2~ "\n99999999~ 36 43 0 #> # ... with 2 more variables: var_type <chr>, rectypes <lgl> ipums_var_desc(ddi, MONTH) #> [1] "MONTH indicates the calendar month of the CPS interview." ipums_var_label(ddi, MONTH) #> [1] "Month" ipums_val_labels(ddi, MONTH) #> # A tibble: 12 x 2 #> val lbl #> <dbl> <chr> #> 1 1 January #> 2 2 February #> 3 3 March #> 4 4 April #> 5 5 May #> 6 6 June #> 7 7 July #> 8 8 August #> 9 9 September #> 10 10 October #> 11 11 November #> 12 12 December