Category: Stata
-
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
-
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
-
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…
-
Create duplicate observations in Stata
For certain cleaning jobs, it can be useful to duplicate an observation (often only temporarily). To create a identical copy of an observation, just type
-
Returning percentiles as scalars
When I wanted to store percentiles in a local, e.g. to indicate the median in a figure, I used to first
-
Recover Stata code from .gph files
If you ever found a good looking Stata figure saved as Stata’s own .gph and wondered how this was produced, you can simply look up the code that is stored in the file’s meta data.
-
Multiple Stata Windows on OS X
Ever wondered how to run regressions on different datasets simulatenously on your Mac? While this is easy in Windows, you have to use the terminal to have several Stata sessions open at the same time.
-
Formatting text in Stata figures
Simple formatting for 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…
-
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).