[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: -log- in Stata to bypass commands that resulted in errors?

From   "Nick Cox" <>
To   <>
Subject   RE: st: -log- in Stata to bypass commands that resulted in errors?
Date   Mon, 3 Nov 2008 11:26:18 -0000

Sergiy is correct in principle, and no doubt he could easily think up
examples in which you would get bitten. 

In practice almost all (well-written) commands kick you out long with an
error before they do anything and above all before they change 
the data or key settings. Also, if your own commands or do-files do
this, the blame is easy to identify. 


Sergiy Radyakin

  in general this does not guarantee however, that once you replay the
resulting list of commands you get the same results as you have when
you saved the list. The commands where errors occured in general could
do actions that changed the data or the settings of Stata that can
affect the further chain of events.

Alan Riley <> wrote:

> Mingfeng Lin ( asked about saving all
> commands which did not result in an error:

>> I'm just curious if there is a way (or maybe an add-on) in Stata to
>> create a log file for only the correct commands? -log using- or -#
>> review- will capture all commands that have been typed in the window,
>> including those resulting in errors.  If there is a way for the log
>> automatically filter out those commands, it would be really nice,
>> especially replicating what we do in an interative manner with Stata.
> It is possible to do this from Stata's Review window, which displays
> a history of commands submitted to Stata.  Follow the steps below
> to save a .do file consisting of all interactive commands which did
> not result in an error.
> There are three columns in the Review window: sequence number (the
> order in which commands were submitted to Stata), command (the command
> itself), and return code (empty if the command completed successfully;
> the return code, or '_rc' from the command if it exited with an
> error).
> After issuing several commands to Stata interactively, some of which
> might have resulted in errors, click on the top of the return code
> (_rc) column in the Review window.  This will sort the commands
> in the Review window such that all the commands which did not result
> in an error are grouped together (and within that group they will
> be in the order in which they were submitted to Stata).  Beneath them
> will be all the commands resulting in errors, sorted by the return
> code.
> The first group is of interest; the second can be ignored.  Select
> all commands in the first group: click once on the first command
> in the group to select it, scroll until the last command in the group
> is visible, and then hold down the shift key while clicking on it
> to select all commands from the first one through the last one in
> the group.
> Once all of the valid commands have been selected, right-click
> in the Review window and choose "Save Selected..." to save those
> to a .do file, or choose "Send to Do-file Editor" to paste those
> into Stata's Do-file Editor.

Regards, Sergiy

> --Alan
> (
> *
> *   For searches and help try:
> *
> *
> *
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index