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
Related Posts with Looping through Import Delimited command using locals
Identify missing valuesHi there, I have a dataset from a survey which has 117 variables (Q1 - Q117) which composed of both …
Variable Names StataI am trying to download a CSV into stata14, however I do not want stata to read the first row as var…
Efficient ways to increment dates by given intervalI am trying to achieve what I believe should be a relatively straight-forward task, which is to incr…
Questions regarding etregress commandHi all, I have a few questions regarding etregress command, since I intend to incorporate that into…
Dummy for non-missing valuesHi there, I have a dataset from a survey which has 117 variables (Q1 - Q117) which composed of both …
Subscribe to:
Post Comments (Atom)
0 Response to Looping through Import Delimited command using locals
Post a Comment