Have you ever got a file with the “.dta” extension and you’re wondering what a hell is this file and how to load it in R? Well, the answer is that the “.dta” files are files from the STATA software and you can load them in R using the “haven” library which is also a library of the “tidyverse” family.
Installation
# The easiest way to get haven is to install the whole tidyverse: install.packages("tidyverse") # Alternatively, install just haven: install.packages("haven")
Load the .dta files
library(haven) # Alternatively # library(tidyverse) df<-read_dta("mydata.dta")
Write .dta files
Finally, you can create .dta files as follows:
write_dta(mtcars, "mtcars.dta")