------------------------------------------------------------------------------- help for storecmd, stowcmd, repcmd -------------------------------------------------------------------------------

Store and repeat commands using characteristics

storecmd charname cmdline

stowcmd charname cmdline

repcmd charname [ , showonly ]


cmdline is any Stata command line.

charname is the name of a Stata characteristic. To avoid confusion with characteristics used by Stata itself, include at least one capital letter in the name.

storecmd executes cmdline. If successful, meaning that there were no errors, cmdline is stored as characteristic _dta[charname].

stowcmd stows away cmdline as characteristic _dta[charname]. cmdline therefore need not be a command that would execute properly at the time it is stowed.

repcmd executes the command stored in characteristic _dta[charname].


showonly shows the command line stored, but does not execute it.


Stata command lines are stored temporarily in memory and they may be stored as desired in text files, commonly .log or .do files.

These commands offer a third possibility: command lines may be stored as characteristics. They may be stored within sessions, and so long as the data file is saved so that these characteristics are included, they may be stored between sessions with the same data file.

Here is one pattern:

1. You develop a complicated command line, possibly after several steps. You want to store it. Type, for example,

. storecmd G graph <complicated details>

The command line

graph <complicated details>

is executed.

If no error occurs, the command line is stored as characteristic _dta[G].

In addition, the command line is placed in the keyboard buffer, so that it can be retrieved for editing.

storecmd G graph <complicated details>

is one line above in the buffer.

2. At any time, to see what commands have been stored, you can type

. char list


. char list _dta

noting that this will list any other characteristics as well.

3. If you wish to save such characteristics with the data file, use the save command.

4. Later, you wish to repeat the command. Type

. repcmd G

The command line stored as characteristic _dta[G] is executed.

In addition, that command line is placed in the keyboard buffer, so that it can be retrieved for editing.

repcmd G

is one line above in the buffer.


Nicholas J. Cox, Durham University, U.K. n.j.cox@durham.ac.uk


Alan Feiveson suggested the original idea. Jeroen Weesie's keyb program was invaluable. Jean Marie Linhart identified a bug and indicated a solution.

Also see

On-line: help for char, keyboard