Home  /  Products  /  Stata 19  /  Do-file Editor enhancements

← See Stata 19's new features

Highlights

  • Customization of autocompletion

  • File templates

  • Customization of highlighting of matches

  • Bracket highlighting

  • Code-folding enhancements

  • Temporary bookmarks

  • Show whitespace in selection

  • Navigator panel

  • See more interface features

The Do-file Editor now provides an even better and more customizable environment for coding in Stata with additional autocompletion, templates, improved code folding, and more.

Stata 19 has the following enhancements to the Do-file Editor:

Autocompletion of variable names, macros, and stored results

If you pause briefly as you type, suggestions of variable names from data in memory, macros, and stored results will appear in addition to the command names and existing words that appeared previously.

Templates

By popular request, you can now save time and ensure consistency when you create new documents in the Do-file Editor by using Stata templates and user-defined templates. You can access templates by using the New > Document from template menu. Selecting an item from the templates menu will open an editor and set the contents of the editor to the contents of the template. You can even define your own templates, and they will appear in the Document from template menu.

Current word and selection highlighting

The Do-file Editor will now highlight all case-insensitive occurrences of the current word under the cursor. It will also separately highlight all case-sensitive occurrences of the current selection. You can limit highlighting of the current word to comments, functions, keywords, macros, and strings.

Bracket highlighting

The Do-file Editor will now highlight the brackets enclosing the current cursor position as you move through the document.

Code-folding enhancements

You can now quickly fold all foldable blocks of code in your do-file by using the Fold all menu item. You can then selectively unfold your code one fold point at a time to show the more important parts of your do-file, or you can use the Do-file Editor’s Unfold all menu item to unfold every fold point. You can also select lines of code and transform them into a foldable block of code by using the Fold selection menu item. This can tidy up your code and increase the code’s readability. In addition, the code-folding feature is now less visually distracting because it uses arrow markers in the code-folding ribbon to indicate whether a code fold is expanded or collapsed and to hide expanded code-fold markers unless the user hovers the mouse over the code-folding ribbon.

Temporary and permanent bookmarks

Stata's Do-file Editor now supports temporary bookmarks in addition to the existing permanent bookmarks. Temporary bookmarks allow you to easily navigate through your do-file without making any permanent changes to its content. These bookmarks can be added to any line of your do-file that does not already have a permanent bookmark and will be removed when your do-file is closed.

Show whitespace and tabs

The Do-file Editor has always allowed you to to display whitespace characters as dots for spaces and arrows for tabs to easily identify whitespace characters from alphanumeric characters. You can now show whitespace characters only within a selection instead of always showing them or not showing them at all.

The Navigation control from previous releases of Stata has been replaced by the Navigator panel. It displays a list of permanent bookmarks and programs that are in a do-file. You can quickly jump to the position of a program or bookmark by double-clicking on the item in the Navigator panel. You can also delete and indent bookmarks from the Navigator panel.

Let's see it work

Below, we show quick demonstrations of the new features.

Autocompletion of variable names, macros, and stored results

You can now write code more easily with autocompletion of variable names.

Macros and stored results are now autocompleted too. Even more, you have control of which types of autocompletion you wish to use and where it should appear. Say that you want autocompletion even while typing comments and strings. You do not wish to autocomplete macro names to avoid confusion. So you choose the Edit option in your Do-file Editor, click on Preferences, go to the Autocompletion tab, and enable these preferences.

Templates

Suppose you want to write a new Stata command, implemented in an ado-file, and make sure it follows Stata standards, especially regarding version control. You can now open a new document from a template. When you select ado, the ado template will be automatically loaded:

You can start with this template and fill in the code to implement your new command.

Do you have your own preferred formatting for do-files and ado-files? You can also create your own templates to make your coding more efficient.

Current word and selection highlighting

In the Do-file Editor, you may want to see all matches to a word or a longer selection. Perhaps you want to find all instances of a variable name, macro, or function. You can now place your cursor on a word or make a selection, and all the matches will be highlighted.

The Do-file Editor allows you to have control over this highlighting. Suppose that you want to see all matches to the macro or function that you click on but that you do not wish to see the matches that are in comments or strings, or matches that are keywords, to avoid confusion. So you choose the Edit option in your Do-file Editor, click on Preferences, go to the Highlighting tab, and enable your preferences.

Bracket highlighting

You want to start coding within a block of code, say, an if block, and you want to confirm you are in fact within the code block and your brackets are balanced. You click within the code block, and the surrounding brackets are highlighted so that you can see where the code block you are in starts and ends.

Code-folding enhancements

When you have programs, forvalues loops, if blocks, and other foldable blocks of code, it can be helpful to fold these so that you can focus on other portions of your code. You can now select the Fold all menu item to quickly fold all foldable lines of code.

Notice that once the code is folded, an arrow pointing to the right appears next to the folded code. You can click on the arrow to unfold one block. Or you can select the Unfold all menu item to unfold all the folded block.

Temporary and permanent bookmarks

There is a line of code that impacts the code you are currently working on, so you need to find it quickly and easily. However, it is not important enough to give it a permanent bookmark, so you decide to toggle a temporary bookmark. You can now find the line quickly by seeing its bookmark icon or by using the Next bookmark and Previous bookmark menu items.

Show whitespace and tabs

Now let's imagine you want to see whitespace but not all the time because it is too distracting. When the Always show whitespace in a selection preference is selected in the Do-file Editor's preferences, you can select some text and see the spaces as dots and the tabs as arrows.

Suppose you are working in a massive document with many important sections. You now can use the Navigator to switch between programs and bookmarks instantly by selecting the items on the list within the panel.

Tell me more

Read more about Stata's Do-file Editor in [R] doedit in the Stata Base Reference Manual.

Learn more about Stata's Do-file Editor.

View all the new features in Stata 19, and, in particular, new in Stata interface.

Ready to get started?

Experience powerful statistical tools, reproducible workflows, and a seamless user experience—all in one trusted platform.