From the course: Introduction to Stata

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Local macros and looping

Local macros and looping - Stata Tutorial

From the course: Introduction to Stata

Local macros and looping

- [Instructor] In this session, we'll explore the concept of macros and loops. Macros are often used for advanced coding purposes, however, they are quite simple to use. Macros are abbreviations for a string of characters or numbers. For example, one of the most common used macros in Stata is to specify a variable list once, and then to recall it again, and again, and again. Macros are also linked to loop functions that alLow you to create a repeat series of commands. For example, imagine you want to create 100 new variables that are all closely related. Do you really need to type out 100 generate commands? Stata's macros come in two different flavors, locals and globals. Local macros are temporary macros, and will disappear after you've executed 'em, and they will only work in one do-file. Global macros are persistent through Stata and all do-files. Until you close your Stata session, after which they also disappear.…

Contents