*! version 0.2 17jan2018

Title

fastreshape -- Efficient implementation of reshape for big datasets

Syntax

long wide
+------------+ +----------------+
| i j stub | fastreshape | i stub1 stub2 |
|------------| <---------> |----------------|
| 1 1 4.1 | | 1 4.1 4.5 |
| 1 2 4.5 | | 2 3.3 3.0 |
| 2 1 3.3 | +----------------+
| 2 2 3.0 |
+------------+

To go from long to wide:

fastreshape wide stub, i(i) j(j)

To go from wide to long:

fastreshape long stub, i(i) j(j)

options

Main
i(varlist) use varlist as the ID variables

j(varname) long->wide: varname, existing variable

wide->long: varname, new variable

string j(varname) is a string variable (default numeric)

Advanced
fast Speed up processing significantly by not sorting reshaped dataset

Description

fastreshape is an efficient implementation of reshape suitable for large datasets. It converts panel data from wide to long form and vice versa.

Options

Main

i(varlist) specifies the variables whose unique values denote a logical observation. i() is required unless using the implicit syntax (see example 2) after having already reshaped once on a given dataset.

j(varname) specifies the variable whose unique values denote a subobservation.

string specifies that j() may contain string values.

Advanced

fast speeds up the processing of reshape significantly by not sorting the dataset post-reshape. By default, fastreshape will not use this option and will sort by i and j (for fastreshape long) or by i (for fastreshape wide). This sort order ensures the output of fastreshape matches that of reshape; however, it is time-consuming to enforce this sort order and unncessary for many data tasks.

Examples

Example 1

Load example dataset 1.

. webuse reshape1, clear

Examine the dataset prior to reshaping.

. list

Reshape the data from wide-form to long-form.

. fastreshape long inc ue, i(id) j(year)

Examine the data after reshaping.

. list