labstore

View the Project on GitHub aarondwolf/labstore

labstore - Preserve, restore, and print variable labels and notes

Version: 1.0.0
Date: January 24, 2026

Installing via net install

To install, user can use the net install command to download from the project’s Github page:

net install labstore, from("https://aarondwolf.github.io/labstore")

Syntax

labstore action [varlist] [, options]

Options

Option Description
action One of preserve, restore, or print; required
varlist List of variables; optional for preserve and restore (defaults to all variables)
labels(name \| none) Associative array name for labels. Default: varlabs. Use labels(none) to skip labels.
notes(name \| none) Associative array name for notes. Default: varnotes. Use notes(none) to skip notes.
replace Overwrite existing labels or notes arrays without error

Description

labstore preserves variable labels and notes in Mata associative arrays before data transformations (such as collapse, reshape, or merge), and restores them afterward. This is useful when operations that modify variables or reduce observations would otherwise lose label and note information.

The program has three main actions:

preserve: Store variable labels and/or notes from the dataset into Mata associative arrays. These arrays remain in memory for later restoration.

restore: Apply stored labels and/or notes from Mata associative arrays back to variables in the current dataset. Variables not found in the arrays are skipped silently.

print: Display the contents of stored labels and/or notes arrays in a formatted table.

Remarks

By default, both labels and notes are preserved/restored using the array names varlabs and varnotes. You can customize these names, or disable labels or notes with labels(none) or notes(none).

For the preserve action, if no varlist is specified, all variables in the dataset are used. For restore, you should specify the variables you want to restore to (typically all variables after a data transformation). For print, varlist is not used.

Labels are stored as Stata variable labels (accessible via label variable). Notes are stored as Stata variable characteristics and retrieved using notes syntax.

If you attempt to preserve with an array name that already exists in memory, labstore will refuse to overwrite unless you specify the replace option.

Examples

Basic workflow: preserve labels and notes, collapse data, then restore:

. sysuse auto
. labstore preserve
. collapse (mean) price mpg weight, by(foreign)
. labstore restore _all

Preserve only labels, omitting notes:

. labstore preserve price mpg rep78, notes(none)

Restore only notes, using a custom array name:

. labstore restore _all, notes(my_notes_backup) labels(none)
. labstore print

Use custom array names for both:

. labstore preserve price-gear_ratio, labels(orig_labels) notes(orig_notes)
. labstore restore _all, labels(orig_labels) notes(orig_notes)

Overwrite existing arrays with replace option:

. labstore preserve _all, replace

Author

Aaron Wolf, Northwestern University
aaron.wolf@u.northwestern.edu

Also see