\begin{Schunk}
\begin{Sinput}
 library(Amelia)
 ## Drop the redundant integer versions of the variables
 dato <- hbsc[ , grep("^.*_i$", colnames(hbsc), invert = TRUE)]
 ## Don't have good reason for emburn setting, but
 ## run was quitting so quickly I was not comfortable
 datoamelia <- amelia(dato, m = 5L, p2s=0,  idvars = "stud_id",
                       ords = grep("^.*_o$", colnames(hbsc), value = TRUE),
                       noms = c("Gender", "Grade"),
                       emburn = c(100L, 10L))
 ## Extract the imputed complete data sets
 imps <- datoamelia$imputations
 ## Now re-create the integer coded variables
 ordvars <- grep("^.*_o$", colnames(imps[[1]]), value = TRUE)
 for(i in seq_along(imps)){
      oneds <- imps[[i]]
      for(j in ordvars){
          newvar <- as.integer(oneds[ , j])
          newname <- gsub("_o$", "_i", j)
          oneds[ , newname] <- as.integer(oneds[ , j])
      }
      imps[[i]] <- oneds
  }
 saveRDS(imps, file.path(wdir, "amelia-imps.rds"))
\end{Sinput}
\end{Schunk}
