adotools is a small collection of Stata utilities for defining, adding, removing, and clearing user-written ado paths. It is useful when working across multiple Stata projects, development folders, or synchronized directories where ado files should be made available only when needed.
Table of Contents
Requires Stata 16.
adodefine [name], path(path) [using(filename)]
adodefine [name], remove [using(filename)]
adodefine, list [using(filename)]
adodefine, clear [using(filename)]
adodefine, from(filename)
adodefine, copy(filename [, excel]) [using(filename)]adoadd namelist [, from(filename) relative(path_prefix)]
adoadd _all [, from(filename) relative(path_prefix)]adorm namelist [, from(filename) relative(path_prefix)]
adorm _all [, from(filename) relative(path_prefix)]adoclear [, clear all]name is the key used to identify an ado directory in the path definition dataset. namelist is one or more stored names. Use _all with adoadd or adorm to add or remove all stored paths.
adotools manages named collections of Stata ado-path entries. The package stores a table of ado directories, usually in adodefine.dta, and lets the user add or remove selected directories from Stata's active adopath by name.
The intended workflow is:
- Use adodefine to create and maintain a dataset containing names and paths.
- Use adoadd to add one or more of those paths to the current Stata session.
- Use adorm to remove one or more of those paths and drop loaded programs from those paths.
- Use adoclear to reset the session and remove nonstandard ado paths.
The path definition dataset contains three variables:
| Variable | Description |
|---|---|
id |
Numeric identifier for the path entry |
name |
Name used by adoadd and adorm |
path |
Directory added to or removed from Stata's ado path |
adodefine maintains the path definition dataset. At least one of path(), clear, remove, list, from(), using(), or copy() is specified depending on the task.
With path(), adodefine adds a new record. If name is omitted, adodefine attempts to use the basename of path() as the name.
With list, adodefine lists the records in the path definition dataset. With remove, it removes the records whose names match name. With clear, it creates a new empty path definition dataset.
adoadd reads the path definition dataset, selects the requested names, and runs adopath + for each selected path. If _all is specified, all paths in the definition dataset are added.
adorm reads the path definition dataset, selects the requested names, drops any currently loaded ado programs found in those directories, and runs adopath - for each selected path. If _all is specified, all paths in the definition dataset are removed.
adoclear can clear the data in memory and/or all frames, then removes nonstandard ado paths from the active Stata ado path. It does not remove Stata's standard path entries BASE, SITE, PERSONAL, PLUS, OLDPLACE, or .. It also rebuilds the Mata library index.
| Option | Description |
|---|---|
path(path) |
Adds path to the path definition dataset under name. If name is omitted, adodefine attempts to use the path basename as the name. |
remove |
Removes the named entries from the path definition dataset. |
list |
Lists the current path definition dataset. |
clear |
Creates a new empty path definition dataset. If using() is specified, the empty dataset is saved there; otherwise the default adodefine.dta is used. |
from(filename) |
Copies an existing path definition dataset to the folder containing adodefine.ado, saving it as adodefine.dta. |
using(filename) |
Specifies the path definition dataset to read from or write to. If the file does not exist, adodefine creates an empty dataset with variables id, name, and path. |
copy(filename [, excel]) |
Copies or exports the path definition dataset. Without excel, the dataset is copied as a Stata dataset. With excel, it is exported to Excel with variable names in the first row. |
| Option | Description |
|---|---|
from(filename) |
Reads path definitions from filename instead of the default adodefine.dta. If the filename has an Excel extension, the file is imported using import excel, firstrow; otherwise it is opened as a Stata dataset. |
relative(path_prefix) |
Prefixes path_prefix to all paths read from the path definition dataset before adding or removing them. This is useful when the stored paths are relative to a project or synchronized folder. |
| Option | Description |
|---|---|
clear |
Clears the current dataset before removing nonstandard ado paths. |
all |
May be combined with clear. Together, clear all is executed before nonstandard ado paths are removed. |
The following examples follow the accompanying example.do file.
Start by clearing the current ado-path definition file and adding project-specific ado directories.
adodefine , clear
adodefine xtdcce2, path("your folder")
adodefine , listadodefine xtdcce2, remove
adodefine , listA separate definition file can be created with using().
adodefine , clear using("your folders")
adodefine xtdcce2, path(folder to path") using("path to ado")Add selected paths:
adoadd xtdcce2Add all paths:
adoadd _allRemove selected paths:
adorm xtdcce2Remove all paths:
adorm _alladoadd xtgetpca, from("my_adodefine.dta")
adoadd xtgetpca, from("my_adodefine.xlsx")adoadd _all, from("adodefine.dta") relative("D:\StataCode\")
adorm _all, from("adodefine.dta") relative("D:\StataCode\")Clear the active dataset and remove nonstandard ado paths:
adoclear, clearClear all frames and remove nonstandard ado paths:
adoclear, clear allInstall from GitHub using Stata's net install command:
net install adotools, from("https://raw.githubusercontent.com/JanDitzen/adotools/main/") replaceAlternatively, clone or download the repository and add the folder containing the ado files to your Stata ado path:
adopath + "path/to/adotools"After installation, type:
help adotoolsEmail: jan.ditzen@unibz.it
Web: www.jan.ditzen.net
Initial public version.