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
simultaneously:
- ----------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 {
continue
}
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)
- ----------
Why do you want the time variables to be 'year1997', 'year1998' and so on?
It would seem obvious that 'year1997' == 1997, or perhaps 1 if it is a
dummy for year, but it would seem sufficient to have a single variable
'year' which contains the year of each chunk of data.