Hi all,
I have an issue with the following loop over text files, stored in the folder US companies and whose names are 1, 2, 3....up to 3290
local files : dir "$path\US companies" files "*.txt"
di `files'
foreach file of local `files' {
import delimited using "$path\US companies\`file'", varnames(1) delim("") bindquotes(loose) stripquotes(yes) clear
keep companyname bvdidnumber nacerev2corecode4digits countryisocode postcode city latitude longitude guobvdidnumber duobvdidnumber
foreach V of varlist _all {
capture confirm string variable `V'
if !_rc {
replace `V' = ustrto(ustrnormalize(`V', "nfd"), "ascii", 2)
replace `V' = ustrtrim(`V')
replace `V' = stritrim(`V')
replace `V' = strlower(`V')
replace `V' = ustrlower(`V')
}
}
save "$path\dta\US_companies\`file'.dta", replace
}
When I run the command the prompt returns me the following error:
_"1.txt invalid name
r(198);
Do you have any idea of why the loop does not work?
Best regards and thank you for any help
I have an issue with the following loop over text files, stored in the folder US companies and whose names are 1, 2, 3....up to 3290
local files : dir "$path\US companies" files "*.txt"
di `files'
foreach file of local `files' {
import delimited using "$path\US companies\`file'", varnames(1) delim("") bindquotes(loose) stripquotes(yes) clear
keep companyname bvdidnumber nacerev2corecode4digits countryisocode postcode city latitude longitude guobvdidnumber duobvdidnumber
foreach V of varlist _all {
capture confirm string variable `V'
if !_rc {
replace `V' = ustrto(ustrnormalize(`V', "nfd"), "ascii", 2)
replace `V' = ustrtrim(`V')
replace `V' = stritrim(`V')
replace `V' = strlower(`V')
replace `V' = ustrlower(`V')
}
}
save "$path\dta\US_companies\`file'.dta", replace
}
When I run the command the prompt returns me the following error:
_"1.txt invalid name
r(198);
Do you have any idea of why the loop does not work?
Best regards and thank you for any help

Comment