I am creating 1 test file for each year from 2001 to 2010. I define some variables for my 2001 file, and then, from 2002 onwards, I want Stata to merge it with the file from the previous year.
My minimum working example looks like this:
set obs 100
g year=2001
g casenum=_n
g yob=1973
save file_2001, replace
forv n=2002(1)2010{
clear
set obs 110
g casenum=_n
g year=`n'
merge 1:1 casenum using file_`n-1', keepusing (yob)
save file_`n', replace
}
The error I get is file_2002.dta not found. Does anyone have any suggestions?
question from:
https://stackoverflow.com/questions/65927622/can-i-name-files-recursively-in-stata 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…