Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: sequential application of a model to a number of datasets in manner of foreach var of varlist


From   "Neil Shephard" <nshephard@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sequential application of a model to a number of datasets in manner of foreach var of varlist
Date   Wed, 19 Apr 2006 09:30:18 +0800

On 4/19/06, Ben Dwamena <bdwamena@med.umich.edu> wrote:
> I wish to empirically compare a linear and nonlinear model using
> sequentially 12 different datasets. How may I specify a looping
> procedure for the datasets in the manner of foreach var of varlist
> x1-x12........instead of writing a do-file for each dataset?

Assuming datasets are called data1.dta, data2.dta,
data3.dta....data12.dta, then something like...

forval x = 1/12{
  use data`x', clear
  regress [etc.]
  nl [etc.]
  [any other commands]
}

..would allow you to do this.

If your filenames are non-sequential then you would use a foreach loop...

foreach x in abc cde efg ghi ijk klm mno{
  use data`x', clear
  regress [etc.]
  nl [etc.]
  [any other commands]
}

HTH's

Neil
--
"Try to learn something about everything and everything about
something." - Thomas H. Huxley

Email - nshephard@gmail.com / neilshep@cyllene.uwa.edu.au
Website - http://slack.ser.man.ac.uk/
Blog - http://slack---line.blogspot.com/
Flickr - http://www.flickr.com/photos/slackline/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index