Combining strings into one variable

I’m again playing around with strings in Stata and need to combine (string) variables with (string) variables as well as strings in locals with string variables. Suppose you have two string variables (strvar1 and strvar2) and want to combine them, you can simply type

Continue reading “Combining strings into one variable”

Check whether variable exists in if-conditions

In some applications, e.g. if you want to save coefficient estimates from a regression with many dummies (e.g. fixed effects), you might want to store coefficients as estimates. In this example, we are interested in storing the estimates of the GROUPVAR dummies, but not the dummies of OTHERVAR. While this is usually straightforward by writing

Continue reading “Check whether variable exists in if-conditions”

Add time stamp to Stata figures

Especially in the early stages of a research project it might be good to “time stamp” figure so that you can later figure out when you created a certain figure. Of course you could just check the date in the explorer / finder, but you can also simply add a note to the figure with time and date of its creation:

Continue reading “Add time stamp to Stata figures”

Formatting text in Stata figures

Simple formatting for text in Stata figures

This is not really new, but still comes in handy when formatting text in Stata figures. With a relatively simple code, you can make write text bold, in italics, and even greek letters.

Continue reading “Formatting text in Stata figures”

Routine to export tables from Stata to LaTeX

When it comes to exporting regression tables from Stata to LaTeX, there are several packages that can be used. For a long time, I used outreg2, but now improved my code for the the estout package by Ben Jann. The remainder of this post describes the routine that works best for, you might want to adjust it for your own purposes. (I actually have written about this package before, this post presents a more elaborated code.) Continue reading “Routine to export tables from Stata to LaTeX”

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”