I have been given a dataset (it is a translation table) to use that is set up in a fairly disorganized fashion. It has multiple variables that contain the same type of IDs (although the values in each vary slightly). I need to merge all of these together into one variable, while keeping the other variables. When I try to use the tempfiles I have saved I receive an invalid file specification error, I'm guessing this is just a syntax error on my part, but I have been unable to find a fix through googling so far. My code:

tempfile baseDict
save "`baseDict'"

keep Main_ID
tempfile MainID
save "`MainID'"

foreach year in 2012/2016 {
use `baseDict'
keep *_`year'
rename ID_`year' Main_ID
tempfile yearIDs
save "`yearIDs'"

use `MainID'
merge 1:1 Main_ID using "`yearIDs'"
save "`MainID'"
}

Set trace seems to show the error ocurring right as the first use `baseDict' runs in the for loop. Any help is quite appreciated, thank you!