DTA (.dta)

Background & Context

    • MIME type: application/x-stata-dta
    • Stata database transport format.
    • Legacy data exchange format.
    • Stores numerical datasets in a portable format.
    • Binary format.
    • Initially developed in 1985 by StataCorp.

Import

  • Import["file.dta"] imports a DTA file, returning all datasets arranged as a table.
  • DTA data is represented in the Wolfram Language by real or integer numbers, strings, Boolean values True and False, and DateObject specifications.
  • Import["file.dta",elem] imports the specified element from a DTA file.
  • Import["file.dta",{elem,suba,subb,}] imports a subelement.
  • The import format can be specified with Import["file","DTA"] or Import["file",{"DTA",elem,}].
  • Export["file.dta",expr] creates a DTA file from expr.
  • Supported expressions expr include:
  • {v1,v2,}a single column of data
    {{v11,v12,},{v21,v22,},}lists of rows of data
    arrayan array such as SparseArray, QuantityArray, etc.
    tseriesa TimeSeries, EventSeries or TemporalData object
    Dataset[]a dataset
    <|"name1"expr1,|>an association of named columns
  • Import and Export support the following data types:
  • "Date"date and time specifications
    "Integer8"8-bit integers
    "Integer16"16-bit integers
    "Integer32"32-bit integers
    "Real32"IEEE singleprecision numbers
    "Real64"IEEE doubleprecision numbers
    "String"string of characters
  • See the following reference pages for full general information:
  • Import, Exportimport from or export to a file
    CloudImport, CloudExportimport from or export to a cloud object
    ImportString, ExportStringimport from or export to a string
    ImportByteArray, ExportByteArrayimport from or export to a byte array

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Data representation elements:
  • "Data"two-dimensional array
    "Dataset"table data as a Dataset
    "LabeledData"association of labels and data
  • Import by default uses the "Data" element.
  • Data descriptor elements:
  • "ColumnDescriptions"description and types of columns
    "Labels"names of columns
    "MissingValues"values to be considered missing per column
  • Metadata elements:
  • "ByteOrdering"endianness of the data
    "CharacterEncoding"character encoding of the file
    "Comments"comments on the file
    "Compression"type of compression used in the file
    "CreationDate"creation date of the document, given as a DateObject
    "Dimensions"dimensions of the data
    "MetaInformation"metadata given as strings and date objects
    "MissingValues"values to be considered missing per column
    "ModificationDate"modification date of the document, given as a DateObject
    "TableName"name of the entire table
    "Version"version of the SAS specification for the file

Options

  • Import options:
  • "ColumnDefaultValues"Automaticassociation of column names and default values
    "TypeDefaultValues"Automaticassociation of types and default values
  • Export options:
  • "ColumnDescriptions"Automaticlist of descriptions for each column
    "MetaInformation"Automaticassociation of metadata tags and values
  • Possible settings for "ColumnDescriptions" include:
  • {"label1", "label2", }list of strings giving column names
    {assoc,}list of associations giving column metadata
    <|colassoc|>association of index or column name and column metadata
  • Possible keys for assoc include:
  • "Name"string giving the column's name
    "Description"string giving the column's description
    "Type"string giving the column's type
  • Possible keys for "MetaInformation" include:
  • "Comments"string giving general comments on the file
    "CreationDate"date object giving the creation date of the file
    "ModificationDate"date object giving the modification date of the file
    "TableName"string giving the name of the entire table
    "Version"integer giving the version of the file

Examples

open allclose all

Basic Examples  (3)

Import a DTA file:

Summary of a DTA file:

Export an array of expressions to a DTA file:

Import the resulting file as a dataset:

Scope  (6)

Export a Dataset:

Column names are automatically inferred:

Export an array of data:

Column names are automatically generated:

Export an association of named columns:

Column names are automatically inferred:

Export a TimeSeries:

Times are stored in the first column, values in the second:

Export tagged missing data:

Ragged arrays are automatically padded on the right and converted to full arrays:

Import Elements  (13)

Data Representation  (3)

"Data"  (1)

Import a DTA file as a 2D list of values:

This is also the default element:

"Dataset"  (1)

Import a DTA file as a Dataset:

"LabeledData"  (1)

Import a DTA file as an association of labels and data:

Data Descriptors  (3)

"ColumnDescriptions"  (1)

Import associations giving the name, description and type for each column in a DTA file:

"Labels"  (1)

Import the names of each column in a DTA file:

"MissingPositions"  (1)

Import associations giving the positions of missing values by column:

Metadata  (7)

"ByteOrdering"  (1)

Import the byte ordering stored in the metadata of a DTA file:

"Comments"  (1)

Import comments stored in the metadata of a DTA file:

"CreationDate"  (1)

Import the creation date:

"Dimensions"  (1)

Import the data dimensions:

"MetaInformation"  (1)

Import an association of all the metadata stored in a DTA file:

"ModificationDate"  (1)

Import the modification date:

"Version"  (1)

Import the version of a DTA file:

Import Options  (2)

"ColumnDefaultValues"  (1)

Missing numerical values are replaced with zero by default:

Use "ColumnDefaultValues" to specify a different default value for specific columns:

"TypeDefaultValues"  (1)

Missing numerical values are replaced with zero by default:

Use "TypeDefaultValues" to specify a different default value for specific types:

Export Options  (2)

"ColumnDescriptions"  (1)

Export different data types:

Columns will automatically infer types based on the data given:

Use "ColumnDescriptions" to specify column types and descriptions:

Import the resulting column descriptions:

"MetaInformation"  (1)

Retrieve the metainformation from a DTA file:

Export a new file with the same metainformation: