Home

Awesome

StatFiles

Project Status: Active - The project has reached a stable, usable state and is being actively developed. Build Status Build status codecov.io

Overview

This package provides load support for Stata, SPSS, and SAS files under the FileIO.jl package.

Installation

Use Pkg.add("StatFiles") in Julia to install StatFiles and its dependencies.

Usage

Load a Stata, SPSS, or SAS file

To read a Stata, SPSS, or SAS file into a DataFrame, use the following julia code:

using StatFiles, DataFrames

df = DataFrame(load("data.dta"))

The call to load returns a struct that is an IterableTable.jl, so it can be passed to any function that can handle iterable tables, i.e. all the sinks in IterableTable.jl. Here are some examples of materializing a Stata, SPSS, or SAS file into data structures that are not a DataFrame:

using StatFiles, DataTables, IndexedTables, TimeSeries, Temporal, Gadfly

# Load into a DataTable
dt = DataTable(load("data.dta"))

# Load into an IndexedTable
it = IndexedTable(load("data.dta"))

# Load into a TimeArray
ta = TimeArray(load("data.dta"))

# Load into a TS
ts = TS(load("data.dta"))

# Plot directly with Gadfly
plot(load("data.dta"), x=:a, y=:b, Geom.line)

Using the pipe syntax

load also support the pipe syntax. For example, to load a Stata, SPSS, or SAS file into a DataFrame, one can use the following code:

using StatFiles, DataFrames

df = load("data.dta") |> DataFrame

The pipe syntax is especially useful when combining it with Query.jl queries, for example one can easily load a Stata, SPSS, or SAS file, pipe it into a query, then pipe it to the save function to store the results in a new file.