Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: -foreach- and -forvalues-

From   "Katsuhide Isa" <[email protected]>
To   <[email protected]>
Subject   st: -foreach- and -forvalues-
Date   Wed, 18 Dec 2002 08:46:27 +0900


I'm trying to merge a collection of dta files and create
new time-variables at the same time.
Specifically, I'd like to execute the following two routines 

----------routine 1----------
foreach file in personnel_1997 personnel_1998 personnel_1999 
personnel_2000  personnel_2001 {
   use "`file'"
   sort id
   save "`file'", replace
   use personnel  /*master file*/
   sort id
   capture confirm variable _merge
   if _rc {
   else {
   drop _merge
   merge id using "`file'"
   save personnel, replace

----------routine 2----------
forvalues i = 1997/2001 {gen year`i' = `i''}


Is it possible to execute the above two routines 
combining -foreach- and -forvalues- simultaneously?
For now, as I don't have a good idea, I repeatedly 
use the following simple routine as for routine 2:

----------routine 2'----------
use personnel_1997, clear
gen year1997 = 1997
save personnel_1997_temp, replace
(and so on)


Any suggestions welcome.
Thanks in advance.


*   For searches and help try:

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