Hello Statalisters,
I've being working all day in a code and i couldn't make it work. Because i'm recieving this error message:
file C:/Users/afede/OneDrive - CAF/RED 2020/Capitulo_5/Material_proyecciones/4.Entregas/Parciales/Salud/191220_11vo_envio/xls/e1_demografia/_e1_het_gedadg.xlsx not found
I think that the code is not recognizing the locals and it's driving me crazy! I can assure you that in that path there are all the `country'_e1_het_gedadg.xlsx files and i've already checked for some spaces in the name of the files.

Let me explaing the task that i'm after. Mainly i'm trying to import from excel some sheets of files by looping over their names, operating in some way and the trying to save then in .dta files
The running locals are country and sheet and i need to use a different procedure for the countries named COL (Colombia) and URY (Uruguay), that's why you will see and if/else statement.

The code is as follows:
Code:
// Rutine 1

cls
clear all
drop _all

* Setting the paths
local output "C:\Users\afede\OneDrive - CAF\RED 2020\Capitulo_5\Material_proyecciones\4.Entregas\Parciales\Salud\191220_11vo_envio\resultados_proyecciones"
local raw "C:\Users\afede\OneDrive - CAF\RED 2020\Capitulo_5\Material_proyecciones\4.Entregas\Parciales\Salud\191220_11vo_envio\xls\e1_demografia"

* Setting local macros for the loops
local country = "ARG BOL CHL MEX PAN PRY PER COL URY"
local sheet = "all pub ss"

* Making the loop
foreach i of local country {

    if "`i'" == "COL" | "`i'" == "URY" {
            foreach j of local sheet {
                display as error "`i'"
                import excel "`raw'/`i'_e1_homo_gedadg.xlsx", sheet("e1_proy_`j'_g") clear
                sxpose, clear force
                destring _v*,replace

                generate pais = "`i'"
                generate subsistema = "`j'"
                
                generate año=.
                local años "2015 2020 2025 2030 2035 2040 2045 2050 2055 2060 2065"
                forvalues i=1/11 {
                    local n: word `i' of `años'
                    replace año = `n' if _n==`i'
                } 
                
                local nombres "e0_14 e15_29 e30_44 e45_64 e65_80 e_mas80 e_agregado"
                forvalues i = 1/7 {
                    local nomb: word  `i' of `nombres'
                    rename _var`i' `nomb'
                }
                save "`output'/`i'_`j'.dta" , replace
            }
    }
    
    else {
            foreach j of local sheet {
                display as error "`i'"
                import excel "`raw'/`i'_e1_het_gedadg.xlsx", sheet("e1_proy_`j'_g") clear
                sxpose, clear force
                destring _v*,replace

                generate pais = "`i'"
                generate subsistema = "`j'"
                
                generate año=.
                local años "2015 2020 2025 2030 2035 2040 2045 2050 2055 2060 2065"
                forvalues i=1/11 {
                    local n: word `i' of `años'
                    replace año = `n' if _n==`i'
                } 
                
                local nombres "e0_14 e15_29 e30_44 e45_64 e65_80 e_mas80 e_agregado"
                forvalues i = 1/7 {
                    local nomb: word  `i' of `nombres'
                    rename _var`i' `nomb'
                }
                save "`output'/`i'_`j'.dta" , replace
            }
    }

}
Can anyone tell me what might be working wrong? I think that, in general, i'm not so sure about the correct quotating and calling for locals when dealing with paht files but everything that i read didn't work.

Thanks and merry christmas to you all!