Multiple lines commands in Stata

Many Stata commands get easily quite long. Take, for example, a command to generate a figure – possibly the layout definitions are quite lengthy and difficult to read. Stretching commands over several lines makes it much easier to write and read, and less prone to errors. 

Continue reading “Multiple lines commands in Stata”

Add current date to Stata file names (and others)

We wrote earlier about how to add time stamps (current date and/or time) to your Stata figures, e.g. to keep track of work in progress results. A similar strategy can be used when storing log-files, which are typically overwritten with a more recent version of the same log.

Continue reading “Add current date to Stata file names (and others)”

Standardize variables by group

Unfortunately, the otherwise great Stata command egen does not allow to standardize variables group, e.g. for each year separately. There is a small get-around by calculating mean and SD first, and then manually creating the standardized the variable (and then you really wonder why this is not implemented in Stata).

Continue reading “Standardize variables by group”

Blockwise copy & paste in Stata

Simple method to clockwise edit text in do-files

I’m not sure whether it is was always there or whether it just came with an update, but finally I have found out how to blockwise copy & paste in the Stata do-file editor. What I used to do with other text editors (mostly with WinEdt), is now possible with Stata’s built-in editor. Continue reading “Blockwise copy & paste in Stata”

Ado-files: check and install automatically

If you need a certain ado-file to run your do-file and you are working on different computers, there is a way that Stata checks whether the needed ado-files are installed and that needed ado-files are automatically installed if they are not yet Continue reading “Ado-files: check and install automatically”

Prevent variable abbreviation in Stata

In many cases, variable abbreviation is a handy tool in Stata (e.g. writing w instead of wage if wage is the only variable name starting with w). When using large numbers of variables with similar names, however, it can be quite dangerous, especially when do-files are run at once.

An easy way to prevent any variable abbreviation is stating:

set varabbrev off, permanent

Technical note: use of quotation marks

Be aware of the proper use of single and double quotation marks when copying Stata or other codes from this blog (but also when copying codes from other websites). Often opening or closing quotation marks are wrongly formatted. Continue reading “Technical note: use of quotation marks”