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
Is there a command for Black Scholes model for American options?I realise there is Code: bsopm for European Option, but I wonder, is there a command for American d…
Adjustments to Esttab Code to Suppress Superfluous Statistics and Display LabelsHello --- I'm hoping to get some assistance adjusting my esttab code (pasted at bottom) to make the …
Cox-regression:proportional hazard test by Schoenfeld residualsHi! I have performed cox-regression on a data set with both continuous and categorical variables. In…
Create new variable with sums of occurrencesHi Statalist Community It is my first post here and I hope it is not a question that is too trivial…
Problems converting string variable to date/time formatHi, I have a date/time variable that is a string and looks as follows: hh.mm.ss DD.MM.YYYY. I'd lik…
Subscribe to:
Post Comments (Atom)
0 Response to Looping through Import Delimited command using locals
Post a Comment