Hi everyone,

I have a folder that contains 26 individual .xlsx files, each named with the name of a country. In a separate folder I have 26 .dta files with named with corresponding country names. I would like to use a loop to import the Excel files and merge in several variables from the corresponding dta file and then save as a new merged file, for each country. I currently have the following code and am getting stuck on the merge file name which I assume has to do with how I'm using the loop indicator in the file path.

When I try with `i', I get the error ".../Merge format `i'.xlsx not found"
with "`i'", I get the error "using required"
and with `"i"', I get the error "too many ')' or ']'"

Any help would be very much appreciated. Thanks.

foreach i in 1/26 {
import excel "C:\...\Merge format\`i'.xlsx", sheet("Labor") firstrow clear
merge 1:1 WP5889 using "C:\...\Merge datasets"`i'".dta", keepusing(P8A P8B P8C)
drop if _merge==2
save `i'_verbatims, replace
}