Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Analysis with STATA

You're reading from   Data Analysis with STATA Explore the big data field and learn how to perform data analytics and predictive modelling in STATA

Arrow left icon
Product type Paperback
Published in Oct 2015
Publisher Packt
ISBN-13 9781782173175
Length 176 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (11) Chapters Close

Preface 1. Introduction to Stata and Data Analytics 2. Stata Programming and Data Management FREE CHAPTER 3. Data Visualization 4. Important Statistical Tests in Stata 5. Linear Regression in Stata 6. Logistic Regression in Stata 7. Survey Analysis in Stata 8. Time Series Analysis in Stata 9. Survival Analysis in Stata Index

Loops in Stata

Loops is a very important concept in Stata. For various calculations and executions, putting code into loops is an extremely useful concept. The command used to create loops in Stata is foreach. The syntax for such a command is as follows:

foreach macro_name in list_name {
command(s)
}

Now, let's take a small example:

Foreach ball_size in ten twenty thirty [
display " 'ball_size' "
]

In this code, ball_size acts as the name of the written macro. It has a list of the elements that need to be part of the macro. Stata's macro processor breaks this list into appropriate sections. In this case, the sections of the current code can be as per the element list, such as ten, twenty, and thirty.

The brackets denote the beginning and the ending of the loop:

  • [: This denotes the beginning of the loop
  • ]: This denotes the end of the loop

The Stata macro processor analyzes the entire list, which is your input in the macro statement. It also identifies all the elements...

You have been reading a chapter from
Data Analysis with STATA
Published in: Oct 2015
Publisher: Packt
ISBN-13: 9781782173175
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime