From the course: Advanced and Specialized Statistics with Stata

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Repeating commands by looping over variables

Repeating commands by looping over variables - Stata Tutorial

From the course: Advanced and Specialized Statistics with Stata

Start my 1-month free trial

Repeating commands by looping over variables

- [Instructor] Let's learn about looping over variables. Creating loops and code is something that is often done by advanced data users and if done correctly, can significantly speed up the workflow. Looping is often invoke, when users want to repeat the same operation or a series of operations many times. Before we continue, please note that you need to know what local and global macros are. If you don't know what these are, you can recap these here. Here's a popular example of when we might want to use a loop structure in a do-file. Imagine we want to do a lot of data manipulation, but the data manipulation has a consistent process. And this particular case, we want to generate a new variable for every variable in our dataset that is the old variable multiplied by 10. Using traditional coding we would have to type out every single variable generation process. The more variables in our data, the more typing we would have to…

Contents