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)”

Use of embedded quotation marks within locals in Stata

Proper use of single and double quotation marks is essential when working in Stata, especially when writing loops where locals can be a huge time and memory saver. The use of single and double quotation marks is rather straightforward (using ` and ‘ for single, and ” for double quotation marks). You can rather easily define a local, e.g. based on the average of a variable

Continue reading “Use of embedded quotation marks within locals in Stata”

Preamble in do-files

When writing a lot of do-files during a research process it is hard to keep track of what a do-file was for, what it needs in terms of input, and what it generates in terms of output. Especially, if you get your paper back from the (journal) referees with comments what you should change, and want to re-run some part of the analysis — a year after you have done it –, it is hard to remember exactly what you need to do.

I use a preamble in my do-files to document (somewhat) this information, but also to set a couple of standard pointers that make my work easier …
Continue reading “Preamble in do-files”

Table of descriptives

Posted by Didier

This illustrates ways to make a tables of descriptives (mean or something else) for many variables (say wage, tenure, education, …) and several groups (say males and female). Neither summarize or tabstat are useful if the variables are many. With summarize, you would need to cut, paste and edit the output in e.g. Excel. With tabstat, the tabel would be too wide. Continue reading “Table of descriptives”

Using locals and loops to generate long strings

The following command can be used to generate a command which consists of several new variables which are generated within a loop.

This could either be done by (e.g. generating a number of log variables)
gen newvar1 = log(var1)
gen newvar2 = log(var2)
etc.
Continue reading “Using locals and loops to generate long strings”