Hi Statalist Users,

I read a text delimited file using the standard command:

> import delimited "G:\Shared drives\Bank Stock Prices\Match\Gary\All_States_Features\AK_Features_ 20191101.txt", varnames(1) encoding(UTF-8)

The command worked as anticipated.

Now, I want to import data for all 50 US states plus some territories, which I save and merge. To do this, I wrote the loop.

foreach x in AK AL AR AS AZ CA CO CT DC DE FL FM GA GU HI IA ID IL IN KS KY LA MA MD ME MH MI MN MO MP MS MT NC ND NE NH NJ NM NV NY OH OK OR PA PR PW RI SC SD TN TX UM UT VA VI VT WA WI WV WY {
local ST "G:\Shared drives\Bank Stock Prices\Match\Gary\All_States_Features""`x'""_Featu res_20191101.txt"
display "`x'"
display "`ST'"
import delimited "`ST'", varnames(1) encoding(UTF-8)
* I have some commands here that save the information that I need as as DTA files. After the loop, I will append them to each other.
clear
}

When I run this code, it returns.

**********************

. foreach x in AK AL AR AS AZ CA CO CT DC DE FL FM GA GU HIIA ID IL IN KS KY LA MA MD ME MH MI MN MO MP
> MS MT NC ND NE NH NJ NM NV NY OH OK OR PA PR PW RI SC SD TN TX UM UT VA VI VT WA WI WV WY {
2. local ST "G:\Shared drives\Bank Stock Prices\Match\Gary\All_States_Features""`x'""_Featu res_201911
> 01.txt"
3. display "`x'"
4. display "`ST'"
5. import delimited ""`ST'"" , varnames(1) encoding(UTF-8)
6. clear
7. }
AK
G:\Shared drives\Bank Stock Prices\Match\Gary\All_States_Features\AK_Features_ 20191101.txt
using required
r(100);

end of do-file

*****************

The display commands tell me that STATA put `x' correctly into the file name, but the import command isn't reading the file name correctly. Can anyone help me get the syntax correct in the important command in my loop.

Thanks

Gary