I am trying to use insheet multiple .xlxs files and then extract filename. This is my code:
Code:
foreach x in country1 country2 country3{
local files : dir "${Data}/Raw/`x'" files "*.xlsx"
foreach f of local files {
import excel "`f'", sheet("Sheet1") cellrange(C11) firstrow
local state=substr("`f'", 1, strlen("`f'") - 5)
gen state = "`state'"
gen country = "`x'"
save "${Data}/Clean/`x'/`state'", replace
}
}
Thank you.
0 Response to insheeting excel files using loop and extracting filename as variable value
Post a Comment