I'm working with a group of datasets that involve different reports over time. Let's say there are 4 of them, namely r1_d1, r1_d2, r2_d1, r2_d2, in which r indicates the report and d indicates a date.

I'm trying to write a loop to append the individual datasets for each report, e.g., r1_d1 and r1_d2 will be appended. However, the following code doesn't work as intended:

Code:
local reports "r1 r2"

local dates "d1 d2"

foreach r of local reports{
    tempfile `x'
    save `x', emptyok
    foreach d of local dates{
        append using "`r'_`d'"
        save "`x'", replace
    }  
}
What I get from running this code is datasets consisting the observations from both types of reports. For example, there are observations only in r1 but now appear in r2. Please help me identify the error.