<jupyter_start><jupyter_text>Convert `dta` to `xls` with Python 3 & Pandas**Introduction**This is a common question presented on many Stata related discussion lists. Of all the occurances, [Stackoverflow](https://stackoverflow.com/questions/2536047/convert-stata-dta-file-to-csv-without-stata-software) has one of the best set of responses.Quick reference for converting dta file to xls.Given without warranty and as is.No promises this will work for all.<jupyter_code>import pandas as pd
cfile = pd.read_stata('yourdtafile.dta')
cwriter = pd.ExcelWriter('yourxlsfile.xls')
cfile.to_excel(cwriter,'sheet1')
cwriter.save()<jupyter_output><empty_output><jupyter_text>Alternatively write to a CSV<jupyter_code>import pandas as pd
cfile = pd.read_stata('http://www.stata-press.com/data/r15/auto2.dta')
cfile.to_csv('auto2.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11371629542790153, 'fraction_numerical': 0.015240328253223915, 'mean_word_length': 6.763636363636364, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '540447', 'license': 'MIT', 'n_tokens_mistral': 306, 'n_tokens_neox': 289, 'n_words': 69, 'path': 'dtaconversion/ConvertDtaToXls.ipynb', 'repo_name': 'adamrossnelson/StataQuickReference', 'size': '853'}