pandas 1.4.2

ParametersRaisesReturnsBackRef

Parameters

fname : path (string), buffer or path object

string, path object (pathlib.Path or py._path.local.LocalPath) or object implementing a binary write() functions. If using a buffer then the buffer will not be automatically closed after the file is written.

data : DataFrame

Input to save

convert_dates : dict

Dictionary mapping columns containing datetime types to stata internal format to use when writing the dates. Options are 'tc', 'td', 'tm', 'tw', 'th', 'tq', 'ty'. Column can be either an integer or a name. Datetime columns that do not have a conversion type specified will be converted to 'tc'. Raises NotImplementedError if a datetime column has timezone information

write_index : bool

Write the index to Stata dataset.

byteorder : str

Can be ">", "<", "little", or "big". default is :None:None:`sys.byteorder`

time_stamp : datetime

A datetime to use as file creation date. Default is the current time

data_label : str

A label for the data set. Must be 80 characters or smaller.

variable_labels : dict

Dictionary containing columns as keys and variable labels as values. Each label must be 80 characters or smaller.

convert_strl : list

List of columns names to convert to Stata StrL format. Columns with more than 2045 characters are automatically written as StrL. Smaller columns can be converted by including the column name. Using StrLs can reduce output file size when strings are longer than 8 characters, and either frequently repeated or sparse.

{compression_options} :
versionadded
versionchanged
value_labels : dict of dicts

Dictionary containing columns as keys and dictionaries of column value to labels as values. The combined length of all labels for a single variable must be 32,000 characters or smaller.

versionadded

Raises

NotImplementedError
  • If datetimes contain timezone information

ValueError
  • Columns listed in convert_dates are neither datetime64[ns] or datetime.datetime

  • Column dtype is not representable in Stata

  • Column listed in convert_dates is not in DataFrame

  • Categorical label contains more than 32,000 characters

Returns

writer : StataWriter117 instance

The StataWriter117 instance has a write_file method, which will write the file to the given :None:None:`fname`.

A class for writing Stata binary dta files in Stata 13 format (117)

Examples

This example is valid syntax, but we were not able to check execution
>>> from pandas.io.stata import StataWriter117
... data = pd.DataFrame([[1.0, 1, 'a']], columns=['a', 'b', 'c'])
... writer = StataWriter117('./data_file.dta', data)
... writer.write_file()

Directly write a zip file >>> compression = {"method": "zip", "archive_name": "data_file.dta"} >>> writer = StataWriter117('./data_file.zip', data, compression=compression) >>> writer.write_file()

Or with long strings stored in strl format >>> data = pd.DataFrame([['A relatively long string'], [''], ['']], ... columns=['strls']) >>> writer = StataWriter117('./data_file_with_long_strings.dta', data, ... convert_strl=['strls']) >>> writer.write_file()

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.frame.DataFrame.to_stata pandas.io.stata.StataWriter117

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/io/stata.py#3091
type: <class 'type'>
Commit: