Home  /  Stata News  /  Vol 40 No 1  /  You asked. We listened! Do-file Editor templates
The Stata News

«Back to main page


You asked. We listened! Do-file Editor templates

In response to numerous requests, we’re thrilled to announce that Do-file Editor templates are available in StataNow. This new functionality allows you to streamline your workflow by starting new scripts directly from predefined templates. Whether you’re working with a built-in Stata template or your own custom one, the process is simple and efficient.

How it works

You can now access these templates directly from the Do-file Editor by selecting the New > Document from template option from the menu. Once you choose a template from the list, the Do-file Editor will open and automatically populate with the contents of the selected template, allowing you to start working immediately.

Let’s explore an example using Stata’s built-in template called ado. When you select this template, Stata automatically opens a new Do-file Editor with a prepopulated structure that looks like this:

ado_template.png

This structure is a skeleton for defining Stata programs. It provides the basic components you need to start writing a program, such as program define, version control, and the end statement. The template is set to use the current version (18.5 in this case). It will automatically update to reflect the version you’re using, so if you upgrade to version 19, 20, or any future release, the template will adjust accordingly.

The section labeled insert code here is where you can begin writing your custom Stata code. This placeholder is designed for you to add the specific functionality and logic that you need for your program. For instance, within this space, you can define variables or perform any data manipulation or analysis relevant to your task.

When you use this template, you don’t have to type these common elements from scratch each time you create a new program. It simplifies the process of writing Stata code, saving you time and reducing the chance of missing essential components. Moreover, you no longer need to recall the syntax or specific formatting needed to define a program in Stata—it’s all set up for you, ready to be customized with your own code.

Custom templates

In addition to using a built-in template, you can create your own custom templates to fit your specific needs. To do this, simply create a directory named document_templates inside your PERSONAL directory. If you’re unsure of the exact location of your PERSONAL directory, you can easily find it by running the adopath command:

. adopath
  [1]  (BASE)      "/usr/local/statanow18/ado/base/"
  [2]  (SITE)      "/usr/local/ado/"
  [3]              "."
  [4]  (PERSONAL)  "~/ado/personal/"
  [5]  (PLUS)      "~/ado/plus/"
  [6]  (OLDPLACE)  "~/ado/"

This will display the paths Stata is currently using. Look for the one labeled as PERSONAL, and inside that directory, create a new directory named document_templates. Once it is set up, you can save your template files into that directory.

Supported file types

The template system supports a variety of plain text files:

  • Stata do-files (.do)
  • Stata ado-files (.ado)
  • Python files (.py)
  • Java files (.java)
  • And more ...

This flexibility allows you to build a repository of templates tailored to your specific coding environment and needs.

Learn more

For more information on this feature, including how to use and manage templates, check out the official documentation:

Check out all the StataNow updates to the Do-file Editor, including autocompletion, highlighting, code folding, and bookmark enhancements.

— Chris Cheng
Senior Econometrician

«Back to main page