1

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?

  • 1
    Hi and welcome to Stackoverflow. If your data is not sensitive, I suggest you share it so that people trying to help you will be able to test possible solutions on their own. – SavedByJESUS Jan 02 '21 at 20:48
  • @SavedByJesus, if OP no longer has a Stata 16 license he/she cannot view or open the .dta data. – Parfait Jan 02 '21 at 22:10

2 Answers2

3

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
JBGruber
  • 11,727
  • 1
  • 23
  • 45
3

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)
Wouter
  • 3,201
  • 6
  • 17