<- See Stata 18's new features
Syntax highlighting of user-defined keywords
Automatic backups and syntax highlighting of user-defined keywords are now available in Stata's Do-file Editor.
Automatic backups. Documents that are open in the Do-file Editor are periodically saved to a backup file on disk. This includes new documents that haven't been saved to disk yet. If your computer were to lose power or crash before you had a chance to save the changes to your document, your unsaved changes can still be recovered. To recover your unsaved changes, open your document in the Do-file Editor again. If a backup file is found in the same location as your document, you will be prompted to recover the backup file or open the document that was last saved to disk. Recovering the backup file will simply load it into the Do-file Editor; it will not overwrite the document that was saved to disk unless you choose to do so.
Syntax-highlight user-defined keywords. Stata's Do-file Editor now includes the ability to syntax highlight user-defined keywords. This will allow you to syntax highlight your favorite community-contributed commands. You simply create a specially named keyword definition file containing a list of keywords, and Stata will syntax highlight those keywords using a settable color and font styles such as bold or italics. You can even create a global keyword definition file that can be shared to all users of the same computer. Each user can still create their own local keyword definition file, and the keywords from both the global file and the local file will be loaded into the Do-file Editor.
While working in the Do-file Editor, disaster strikes and a brownout occurs. We temporarily lose power, and all our unsaved edits to our do-file are seemingly lost. However, Stata’s Do-file Editor had been saving our edits periodically to a backup file. When we attempt to open our do-file again, the Do-file Editor notices that there is a backup file and presents us with the option to recover the backup.
We click the Recover backup button to recover the backup file. Stata opens the backup file in the Do-file Editor and deletes the backup file from disk. You can now choose to save the backup file or just close it to discard the changes. To prevent you from accidentally overwriting the original file, Stata uses a different filename by adding the string [Recovered] to the filename. When saving the recovered file, you can save it as a new file or overwrite the original file.
If we had clicked the Open original button, the original file would have been opened in the Do-file Editor and the backup file would have been deleted. If we had clicked the Cancel button, no file would have been opened and the backup file would remain on disk. We would then be able to recover the backup file later.
Our do-file stpm2.do reproduces the examples in the postestimation help file for the community-contributed command stpm2, which fits flexible parametric survival models. These examples explore the effect of hormonal therapy on recurrence time using the brcancer.dta breast cancer dataset. With our do-file loaded into Stata’s Do-file Editor, Stata commands such as webuse, stset, and predict are syntax highlighted, but the community-contributed command stpm2 is not. We'll fix that by creating a text file containing the keyword stpm2 and saving the file as stata-userkeywords.txt in our home directory. After restarting Stata and opening our do-file in the Do-file Editor again, we now see that the stpm2 command is syntax highlighted as a user-defined keyword.
Learn more about Stata's Do-file Editor ->
Read more about Stata's Do-file Editor in the Stata Base Reference Manual; see [R] doedit ->
View all the new features in Stata 18 ->