6 [ GSM ] 13 Using the Do-file Editor—automating Stata
Matching and balancing of parentheses ( ), braces { }, and brackets [ ] are also available from
the Edit menu. When you select Edit > Find > Match brace, the Do-file Editor looks at the character
immediately to the left and right of the cursor. If either is one of the characters that the editor can
match, the editor will find the matching character and place the cursor immediately in front of it. If
there is no match, the menu item will be inactive.
When you select Edit > Find > Balance braces, the Do-file Editor looks to the left and right
of the current cursor position or selection and creates a selection that includes the narrowest level
of matching characters. If you select Balance braces again, the editor will expand the selection to
include the next level of matching characters. If there is no match, the cursor will not move. Balancing
braces is useful for working with complicated expressions or blocks of code defined by loops or if
commands. See [P] foreach, [P] forvalues, [P] while, and [P] if for more information.
Balance braces is easier to explain with an example. Type (now (is the) time) in the Do-file
Editor. Place the cursor between the words is and the. Select Edit > Find > Balance braces. The
Do-file Editor will select (is the). If you select Balance braces again, the Do-file Editor will select
(now (is the) time).
Text in Stata strings can include Unicode characters and is encoded as UTF-8 (see [U] 12.4.2 Handling
Unicode strings). However, you may have do-files, ado-files, or other text files that you used with
Stata 13 or earlier, and those files contain characters other than plain ASCII such as accented characters,
Chinese, Japanese, or Korean (CJK) characters, Cyrillic characters, and the like. If you open a file
that is not encoded in UTF-8, Stata prompts you to specify the encoding for the file so that it can
convert the file to UTF-8. If you cancel the conversion or choose the wrong encoding, you can try the
conversion again later using Convert to UTF-8. The conversion to UTF-8 can be undone by using
Edit > Undo and is not permanent until you save the do-file. For Stata datasets with characters
not encoded in UTF-8 or for bulk conversion of multiple Stata files, you should use the unicode
translate command.
Editing tip: You can split the Do-file Editor window vertically by clicking on the Split window
button in the status bar . This is useful for looking at two widely separated places in a file at the
same time. To go back to a single pane view, click on the close button in either of the split panes.
The View > Do-file Editor menu
You have already learned about the Do button. Selecting View > Do-file Editor > Execute (do)
is equivalent to clicking on the Execute (do) button.
Selecting View > Do-file Editor > Execute (do) from top will send all the commands from the
first line to the current line to the Command window. This method is a quick way to run a part of a
do-file.
Selecting View > Do-file Editor > Execute (do) to bottom will send all the commands from the
current line through the end of the contents of the Do-file Editor to the Command window. This
method is a quick way to run a part of a do-file.
Selecting View > Do-file Editor > Execute quietly (run) is equivalent to View > Do-file Editor
> Execute (do), but the commands will be executed quietly; that is, no output will be displayed
in the Command window.
Selecting View > Do-file Editor > Execute (do) line will send all the commands from the current
line to the Command window. The cursor will then automatically advance to the next executable line,
bypassing empty lines and comments. This method is an easy way to run a do-file line by line.