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

* StandardizeVAR by year
by year: egen VAR_mean= mean(VAR)
by year: egen VAR_sd = sd(VAR)
by year: gen VAR_std = (VAR-VAR_mean)/VAR_sd

or, if you need to do it for several variables at once

* StandardizeVAR1 VAR2 VAR3 by year
foreach var of varlist VAR1 VAR2 VAR3 {

by year: egen `var'_mean= mean(`var')
by year: egen `var'_sd = sd(`var')
by year: gen `var'_std = (`var'-`var'_mean)/`var'_sd
}

Dialog box in Stata

Sometimes it is useful to have the dialog box for Stata commands, especially for the ones where the syntax is complex, such as the graphic commands. If you know the name of the command (e.g. regress)  but you don’t know how to access the dialog box from the drop down menus, you can always type:

db COMMAND (e.g. db regress)

in the Stata command interface. This will bring up the dialog box. It is a very useful shortcut, although it sometimes fosters “irresponsibility”, since it makes it extremely easy to apply methods you do not fully understand.

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