Dear Stata users,
I wanted to right a loop to import a multiple Excel files. I have data on export for 26 countries. Each file starts from a given country name. I wrote a loop:
I wanted that Stata takes every Excel file beginning from a given country name, eg. I have 9 files for Australia and every begins from "AUS_"
However, I see an error :file AUS* not found
I wanted to try something more general and tried a code:
I don't know what's wrong with local but Stata doesn't see it and I have an error:
file U:/CEPII CHELEM/CHELEM ISIC/All/'file' not found
I don't know why Stata doesn't take file with xlsx
I wanted to right a loop to import a multiple Excel files. I have data on export for 26 countries. Each file starts from a given country name. I wrote a loop:
Code:
foreach country in AUS AUT BEL CAN CHE CHN CZE DEU DNK ESP FIN FRA GBR GRC ISR ITA JPN KOR NLD NOR NZL PRT RUS SWE TUR USA{ import excel "`country'*", sheet("annual") firstrow case(lower) save "`country'*", replace }
However, I see an error :file AUS* not found
I wanted to try something more general and tried a code:
Code:
global dir "U:\CEPII CHELEM\CHELEM ISIC\All" local files: dir "$dir" files "*.xlsx", respectcase foreach file in 'files' { clear import excel using "$dir\'file'", firstrow save "$dir\'file'.dta", replace }
file U:/CEPII CHELEM/CHELEM ISIC/All/'file' not found
I don't know why Stata doesn't take file with xlsx
Comment