Reading IPUMS-DHS data into R

I am using IPUMS-DHS data for a project, and I think I encountered a potential error when using the R command to import the data into my R session.

ddi <- read_ipums_ddi("ipums_data/idhs_00004.xml")
data <- read_ipums_micro(ddi)

Specifically, when I downloaded variables with high decimal precision, like NDVI, CROPLAND, etc. (e.g. 0.34543), the file stores these values as an integer and all of them are “0”. Even when I try to convert from integer into double, this does not seem to resolve the issue. This may be a user-error on my part, but am wondering if there may be something going on with the underlying function when it stores the NDVI, CROPLAND variables as integers.


This is an issue we have come across before and are working to fix. Until then, you should be able to work around the issue by modifying this code:


vars_that_should_be_doubles <- c(“NDVI”, “CROPLAND”)

ddi <- read_ipums_ddi("path/to/ddi/filename.xml")
ddi$var_info <- ddi$var_info %>% 
    var_type = if_else(
      var_name %in% vars_that_should_be_doubles),
data <- read_ipums_micro(ddi)