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)

Arguments

object

A DDI object (loaded with read_ipums_ddi), a data.frame with ipums metadata attached, or a single column from an ipums data.frame.

vars

dplyr select-style notation for the variables to give information about

var

select-style notation for a single variable

ipums_var_info() loads all available variable information for one or more variables into a data.frame. If object is a vector, it will include the variable label, variable description and value labels. If object is a data.frame, it will include it for all variables (or only those specified by vars). If it is a DDI, it will also include information used to read the data from disk, including start/end position in the fixed-width file, implied decimals and variable type.

ipums_var_desc() loads the variable description for a single variable.

ipums_var_label() loads the short variable label for a single variable.

ipums_val_labels() loads the value labels 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 read_ipums_ddi. Then you can refer to the IPUMS documentation in this object.

Value

ipums_var_info returns a tbl_df data frame with variable information, and the other functions return a length 1 character vector.

Examples

ddi <- read_ipums_ddi(ipums_example("cps_00006.xml"))

ipums_var_info(ddi)
#> # A tibble: 8 × 10
#>   var_name var_la…¹ var_d…² val_la…³ code_…⁴ start   end imp_d…⁵ var_t…⁶ recty…⁷
#>   <chr>    <chr>    <chr>   <list>   <chr>   <dbl> <dbl>   <dbl> <chr>   <lgl>  
#> 1 YEAR     Survey … "YEAR … <tibble> "\nYEA…     1     4       0 numeric NA     
#> 2 SERIAL   Househo… "SERIA… <tibble> "\nSER…     5     9       0 numeric NA     
#> 3 HWTSUPP  Househo… "HWTSU… <tibble> "\nHWT…    10    19       4 numeric NA     
#> 4 STATEFIP State (… "STATE… <tibble>  NA        20    21       0 integer NA     
#> 5 MONTH    Month    "MONTH… <tibble>  NA        22    23       0 integer NA     
#> 6 PERNUM   Person … "PERNU… <tibble> "\nPER…    24    25       0 numeric NA     
#> 7 WTSUPP   Supplem… "WTSUP… <tibble> "\nWTS…    26    35       4 numeric NA     
#> 8 INCTOT   Total p… "INCTO… <tibble> "\n999…    36    43       0 numeric NA     
#> # … with abbreviated variable names ¹​var_label, ²​var_desc, ³​val_labels,
#> #   ⁴​code_instr, ⁵​imp_decim, ⁶​var_type, ⁷​rectypes
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 × 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