*! version 1.0 20 September 2018
help for statacmds version 1.0 (20 September 2018)

Title

statacmds -- get list of all commands known to Stata, including (Stata/Mata/egen) functions and built-ins

Table of contents

Syntax
Description
Options
Remarks
Examples
Author
Saved results
Also see

Syntax

statacmds [, options]

Search paths
nopersonalfiles don't search in Stata's PERSONAL directory

noplusfiles don't search in Stata's PLUS directory

nooldplacefiles don't search in Stata's OLDPLACE directory

nouserfiles don't search in Stata's PERSONAL, PLUS or OLDPLACE directories

nobasefiles don't search in Stata's BASE directory

nositefiles don't search in Stata's SITE directory

adopath search in Stata's complete adopath, not just system directories

Results
nobuiltins don't return built-in commands

noadocommands don't return commands implemented as ADO files

nofunctions don't return Stata functions

nomatafunctions don't return Mata functions

noegenfunctions don't return egen functions

noabbreviations don't return command abbreviations

Other
noaliasfiles don't parse alias help files

unclassified also return commands that could not be classified as one of the above

verbose give verbose output

Output
saving(filename [, savingoptions]) save results to filename in addition to returning them in r()

Options for saving()
replace replace filename if it already exists

nocategories don't write categories to output file

separator(string) use string as separator between results and categories (default: " ")

Description

statacmds searches for Stata commands or functions (including Mata and egen functions)alongside Stata's system directories (see help sysdir). It is inspired by the searchJeff Pitblado's getcmds (available from https://www.stata.com/users/jpitblado).

In addition, statacmds adds more flexibility to getcmds' approach:

- categorize each command in built-in vs. ado-command

- disable search in alias help-files

- disable returning abbreviations

- return results in r()

- customization of the file paths that are searched

- find Stata functions, Mata functions, and egen functions (some restrictions apply, see remarks)

Options

Search paths

By default, statacmds searches for commands in Stata's system directories (see help sysdir).You can find out where these directories are on your own machine by executing sysdir list).

The search path can be fine-tuned by excluding single system directories via the options nopersonalfiles,noplusfiles, nooldplacefiles, nobasefiles or nositefiles (or a combination of them).The additional option nouserfiles is a convenience shorthand to specifying the three of nopersonalfiles noplusfiles nooldplacefiles.

There is a difference between Stata's system directories and the complete list of directories Stata searches for commands; the latter is called the adopath (see help adopath).Option adopath makes statacmds search alongside the complete adopath instead of Stata's system directories only.This option can be combined with the other options to change the list of directories to search (e.g. adopath nopersonal).

Results

After finding all possible commands, statcmds classifies each into one of the five categoriesbuilt-in, adocommand, Stata function, Mata function, or egen function(details on the classification heuristic can be found in remarks).Returned results can be filtered by adding one or more of the options nobuiltins, noadocommands,nofunctions, nomatafunctions, noegenfunctions.Each of them will disable returning the elements of their respective category.

Additionally, the option noabbreviations, if specified, will disable returning command abbreviations.

Other

With option noaliasfiles specified, statacmds will not read and parse alias help files;specifying this option most likely will lead to a speed up in search time,to the price of not finding functions, built-in commands and command abbreviations. Seldomly used.

The special option unclassified will make statacmds return elements of a residual category:Any command that can not be classified by the heuristic will be returned as category unclassified. Seldomly used.

statacmds will show details on what it is doing if option verbose is specified.

Output

The option saving(filename , savingoptions) makes statacmds, in addition to returning results in r(),save the results to filename; savingoptions can be used to customize details of the saved file (see below).

Savingoptions

When saving the output file, replace will overwrite the file if it already exists.

Writing each command's category to the outputfile can be suppressed with nocategories;this will produce roughly the same output file as getcmds.

Note that the sort order of commands inside of the file may be different to getcmds' result.

When writing the outputfile, separator(string) will make statacmd use stringas separator between results and categories in the file;default is to use a space character as delimiter: "generate builtin".

This option will be ignored if nocategories is specified.

Remarks

In order to retrieve all command names that Stata is aware of, statacmds searches for ado files and help files.Additionally, it reads and parses the alias files of Stata's help file system to find even more files.

After scraping these sources, the results are classified according to the following heuristic:

- any file with file extension .mata is a matafunction

- any help file, or help alias entry, that is accompanied by an ado file with the same name is an ado command

- any other help file or help alias entry that starts with "mf_", or "f_m4_", or "f_m5_", or "mata_" is a mata function

- any other help file or help alias entry that starts with "f_egen" is an egen function

- any other help file or help alias entry that starts with "f_" is a function

- any file with file extension .ado that is accompanied by a help file with the same name is an ado command

- any other file with file extension .ado that starts with "_gsem", "_gs", "_gr" or "_gset" is an ado command

- any other file with file extension .ado that starts with "_g" and is not accompanied by a help file with the same name is an egen function

- any other entry that is found is tested to be a command; if a file with file extension .ado is found in the search path,it is an ado command, otherwise it is a built-in command.

Executing the above heuristical classification necessarily has its shortcomings.Some of the rules pointed out here may lead to erroneous classifications.All but the very last rule lack a good method for cross-checking if the class assignmeht in fact is correct.Finally, all but the last rule make the assignment by certain file naming conventions.If the convention is badly formulated, the assignment has to be wrong.The same applies if, for whatever reason, files do misobey the said convention.

This program currently is not capable of detecting multi-word commands (e.g. duplicates report, graph twoway, odbc query).Feedback with ideas for implementing this, or for other further improvement, as well as feature requests, are of course very welcome.

The source code of the program is licensed under the GNU General Public License version 3 or later.The corresponding license text can be found on the internet at http://www.gnu.org/licenses/ or in gnugpl.

Examples

Find all commands in Stata's BASE and SITE directories:

. statacmds , nouserfiles

Find all commands in Stata's adopath, but skip BASE and PERSONAL directories:

. statacmds , nobasefiles nopersonalfiles adopath

Do the same, but don't return command abbreviations:

. statacmds , nobasefiles nopersonalfiles adopath noaabreviations

Find all commands in Stata's system directories, and save into CSV file commands.csv:

. statacmds , saving(commands.csv , separator(","))

Mimic getcmds using commands.txt:

. statacmds , nofunctions nomatafunctions noegenfunctions saving(commands.txt , nocategory)

Mimic getcmds using commands.txt , nonado:

. statacmds , nofunctions nomatafunctions noegenfunctions noadocommands saving(commands.txt , nocategory)

Mimic getcmds using commands.txt , adoonly:

. statacmds , nofunctions nomatafunctions noegenfunctions nobuiltins saving(commands.txt , nocategory)

Author

Daniel Bela (daniel.bela@lifbi.de), Leibniz Institute for Educational Trajectories (LIfBi), Germany.

Saved results

statacmds saves the following in r():

Locals

r(builtins) list of built-in commands (unless nobuiltins is specified)

r(adocommands) list of commands implemented as ADO files (unless noadocommands is specified)

r(functions) list of Stata functions (unless nofunctions is specified)

r(matafunctions) list of Mata functions (unless nomatafunctions is specified)

r(egenfunctions) list of egen functions (unless noegenfunctions is specified)

Also see

Help: sysdir, adopath, getcmds (if installed)