Skip to content

Instantly share code, notes, and snippets.

@AndreaPasqualini
Created May 22, 2019 09:48
Show Gist options
  • Save AndreaPasqualini/2b7168dd58e322c11d72b36c3835f5f2 to your computer and use it in GitHub Desktop.
Save AndreaPasqualini/2b7168dd58e322c11d72b36c3835f5f2 to your computer and use it in GitHub Desktop.
A CLI tool to convert a Stata .dta file into a .csv file. Relies on pandas.
"""
Title: dta_to_csv.py
Author: Andrea Pasqualini
This CLI tool converts a Stata .dta file into a .csv file. Python3 and pandas
are dependencies. It does not return anything, internally. It saves on disk a
file with CSV extension that has the same name as the input DTA file.
USAGE
-----
python dta_to_csv.py dtafile.dta
"""
from sys import argv
from pandas import read_stata
if __name__ == '__main__':
dtaFile = argv[1]
fName = dtaFile[ : -4 ]
csvFile = fName + '.csv'
read_stata( dtaFile ).to_csv( csvFile )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment