statsmodels.iolib.foreign.StataReader

class statsmodels.iolib.foreign.StataReader(fname, missing_values=False, encoding=None)[source]

Stata .dta file reader.

Provides methods to return the metadata of a Stata .dta file and a generator for the data itself.

Parameters
filefile-like

A file-like object representing a Stata .dta file.

missing_valuesbool

If missing_values is True, parse missing_values and return a Missing Values object instead of None.

encodingstring, optional

Used for Python 3 only. Encoding to use when reading the .dta file. Defaults to locale.getpreferredencoding

See also

statsmodels.iolib.foreign.genfromdta, pandas.read_stata, pandas.io.stata.StataReader

Notes

This is known only to work on file formats 113 (Stata 8/9), 114 (Stata 10/11), and 115 (Stata 12). Needs to be tested on older versions. Known not to work on format 104, 108. If you have the documentation for older formats, please contact the developers.

For more information about the .dta format see http://www.stata.com/help.cgi?dta http://www.stata.com/help.cgi?dta_113

Methods

dataset([as_dict])

Returns a Python generator object for iterating over the dataset.

file_format()

Returns the file format.

file_headers()

Returns all .dta file headers.

file_label()

Returns the dataset’s label.

file_timestamp()

Returns the date and time Stata recorded on last file save.

variables()

Returns a list of the dataset’s StataVariables objects.