Useful Commands in Programs


quietly runs the command but suppresses the output.

Try running the commands below. Compare
. sysuse auto
. quietly reg price mpg if foreign
. predict fv if e(sample)

. reg price mpg if foreign
. predict fv if e(sample)

In this example we do not care so much about the regression outputs but rather the predictions in the estimated sample. Thus we asked Stata to suppress the reg outputs.

preserve; restore

In pair, preserve and restore preserves and restores data. This is useful when we want to keep the original data untouched when a program ends while some damage needs to be done while we run the program.

Compare what the dataset would be like with and without preserve and restore.
. sysuse citytemp
. preserve
. collapse (mean) heatdd, by(region division)
. list heatdd
. restore

Without preserve and restore, after a collapse the dataset will be aggregated to summary statistics and thus the original dataset will be damaged.
. collapse (mean) heatdd, by(region division)

Author: Yun Dai, 2018