Skip to content

Latest commit

 

History

History
79 lines (60 loc) · 1.55 KB

table-interface.md

File metadata and controls

79 lines (60 loc) · 1.55 KB

Table Interface

This page provides further details on the interface of ReadStatTable.

ReadStatTable

Data Columns

As a subtype of Tables.AbstractColumns, commonly used methods including those defined in Tables.jl are implemented for ReadStatTable.

using ReadStatTables, Tables
tb = readstat("data/sample.dta")

A column can be accessed either by name or by position via multiple methods:

tb.mynum
tb[:mynum]
Tables.getcolumn(tb, :mynum)
tb[2]
Tables.getcolumn(tb, 2)

To check whether a column is in a ReadStatTable:

haskey(tb, :mynum)
haskey(tb, 2)

To check the number of rows in a ReadStatTable:

Tables.rowcount(tb)
size(tb, 1)

To check the number of columns in a ReadStatTable:

length(tb)
size(tb, 2)

Iterating a ReadStatTable directly results in iteration across columns:

for col in tb
    println(eltype(col))
end

Data Values

In addition to retrieving the data columns, it is possible to directly retrieve and modify individual data values via getindex and setindex!:

tb[1,1]
tb[1,1] = "f"
tb[1,1]
tb[1,:mylabl]
tb[1,:mylabl] = 2
tb[1,:mylabl]
tb[1,:mydate]
tb[1,:dtime]

Notice that for data columns with value labels, these methods only deal with the underlying values and disregard the value labels. Similarly, for data columns with a date/time format, the numerical values instead of the converted Date/DateTime values are returned.