Read and write Stata DTA files from TypeScript.
toStata(df) serializes a DataFrame to a Stata DTA v118 binary buffer.
readStata(buf, options) parses the buffer back into a DataFrame.
Numeric missing values are represented as null. Mirrors
pandas.read_stata() and DataFrame.to_stata().
Edit any code block below and press ▶ Run
(or Ctrl+Enter) to execute it live in your browser.
Create a DataFrame, serialize it to a Stata DTA v118 binary buffer with
toStata(), then parse it back with readStata().
All columns, values, and shape are preserved.
Stata represents missing numeric values as special sentinel bit patterns.
readStata maps all missing sentinels to null.
toStata writes the standard Stata system-missing value for each type.
Embed a dataset description with dataLabel and per-column annotations
with variableLabels. These metadata fields are stored in the DTA header
and are visible in Stata's describe command.
Restrict columns with usecols, limit rows with nRows,
and promote a column to the DataFrame index with indexCol.
Boolean values are stored as Stata byte (int8) with
true → 1 and false → 0. Reading converts
them back to numbers; use .map() or comparison operators
to recover booleans if needed.
Pass writeIndex: true to include the DataFrame's row index
as an extra _index column in the DTA file.