Stata
Products Purchase Support Company
Search
   >> Home >> Resources & support >> FAQs >> Programming Stata

How do I process parallel lists?

Title   Looping over parallel lists
Author Kevin Crow, StataCorp
Date December 2004; modified April 2005

You can loop over parallel lists in Stata using the forvalues command and the extended macro function : word #. For example, let us say that you had two lists, cat dog cow pig and meow woof moo oinkoink. In a loop, you would like to have the first iteration be cat and meow, the second iteration be dog and woof, etc. Below is the forvalues command you would use.

. local agrp "cat dog cow pig"

. local bgrp "meow woof moo oinkoink"

. local n : word count `agrp'

. forvalues i = 1/`n' {
  2.    local a : word `i' of `agrp'
  3.    local b : word `i' of `bgrp'
  4.    di "`a' says `b'"
  5. }
cat says meow
dog says woof
cow says moo
pig says oinkoink
FAQs
What's new?
Statistics
Data management
Graphics
Programming Stata
Mata
Resources
Internet capabilities
Stata for Windows
Stata for Unix
Stata for Macintosh
Technical support
Resources & support
FAQs
Technical support
NetCourses
Short courses
Users Group meetings
Statalist
Links
Software updates
Software archives
Customer service
Manuals & supplements
Stata Journal
STB
Stata News
Stata Automation
Plugins

Site overview
Products
Resources & support
Company
Site index

© Copyright 1996–2008 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index