Amy
Amy

Reputation: 35

How to save dta file in pandas?

I used this code df = df.to_dta("file_name.dta") to save stata file. It gives me this error:

AttributeError: 'DataFrame' object has no attribute 'to_dta'

Does anybody know what is the correct code to save a Stata .dta file in python?

Upvotes: 1

Views: 840

Answers (2)

Victor Omondi
Victor Omondi

Reputation: 58

use the pandas to_stata DataFrame method.

df.to_stata("file_name.dta")

Read the documentation: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_stata.html

Upvotes: 1

DYZ
DYZ

Reputation: 57033

The method name is .to_stata(), not .to_dta().

Upvotes: 0

Related Questions