Opening Stata 16 .dta in R or Python?

1.7k Views Asked by At

I lost access to my Stata license and need to edit some .dta files for a school project. I've already tried the solutions in this post and this post, but I keep getting error messages saying that they're not Stata 5-12 files (in R) and that they're not Stata 11-15 files (in Python). Is there a way to open Stata 16 .dta files in either R or Python and edit them? If editing's not possible, is there a way to at least convert them into a .csv or .xslx?

2

There are 2 best solutions below

0
JBGruber On

In R

To import:

# install.packages("rio")
data <- rio::import("file.dta")

To export:

rio::export(data, "file.xlsx") # or .csv or a few other formats
0
Wouter On

In Python:

# Import data
import pandas as pd
df = pd.read_stata('filename.dta')

# Possibly edit the DataFrame here

# Save as dta
df.to_stata('filename.dta', write_index=False)

# Save as csv
df.to_csv('filename.csv', index=False)