Search code examples
rr-haven

Haven package adding labels to stata data


I have a Stata data-set with 0,1 I am reading into R using

aa <- haven::read_dta("trial_data.dta")
table(aa$malpos)

Link to data

When its loaded in R the variable is comes in with 1,2 categories instead of 0,1. Is there a way I can avoid this?


Solution

  • simply try this:

    library(dplyr)
    library(haven)
    
    aa %>%
      as_factor()