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 - 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.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Recoding an existing variable4m 3s
-
(Locked)
Generating a new variable5m 15s
-
(Locked)
Naming and labeling variables5m 20s
-
(Locked)
Extended generate3m 26s
-
(Locked)
Indicator variables4m 7s
-
(Locked)
Keeping and dropping variables3m 9s
-
(Locked)
Saving data3m 6s
-
(Locked)
Merging and appending6m 54s
-
(Locked)
String variables5m 53s
-
(Locked)
Local macros and looping7m 12s
-
(Locked)
Manipulating data: Challenge45s
-
(Locked)
Manipulating data: Solution4m 7s
-
(Locked)
-
-
-
-
-
-
-