Globals are ways to use shortcuts in STATA. Think of them of ways of carrying a bunch of information but in just one word. Here are some examples:
sysuse auto
global variables "make price mpg rep78"
* here I'm creating the global names variables, and it contains a bunch of
* variables. Now instead of typing all those variables, I'll just
* call on the global, by using the dollar sign:
sum $variables
Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
make | 0
price | 74 6165.257 2949.496 3291 15906
mpg | 74 21.2973 5.785503 12 41
rep78 | 69 3.405797 .9899323 1 5
This works nicely when you are trying to run a bunch of regressions with a bunch of controls, or if you want different controls in different regressions you can think of creating a global called “controls1” and another one called “controls2”
Another great way of using globals, are for filepaths. For example say all your work for one project is on one folder named “hw1” or “projectx” then you want to put a bunch of output in that filepath, and instead of always wondering where that filepath is you can defined it at the beginning of your dofile. For example, I just downloaded some data from github, and I’ll output stuff to the downloads folder, so I can create a global called “downloads” that will point to the download folder.
global downloads "/Users/laptop/Downloads/"
use "$downloads/dataset_2.13.dta", clear