Hi all,
Fancy new digs!
I am trying to execute a look that pulls in all *.txt files in a folder and then saves each one in another folder as a *.dta file. I am having trouble with the code.
This is what I have (more or less):
**** start ado****
cd "B:\OtherDatabase\folderA"
local files : dir . files "*.txt"
foreach f of local files {
insheet using "`f'", delim("|") names clear //pulls in the .txt file
* create a bunch of new variables, rename variables etc...
cd "B:\OtherDatabase\folderB" //changes to a new folder
save "`f'", replace //saves the file - but in this case, saves it as a *.txt file
cd "B:\OtherDatabase\folderA" //back to the other folder to read in the next file
}
*
**** end ado *****
Ideally I would be able to have <save "`f'", replace> save a *.dta file but instead it saves a *.txt file because that is what is stored in `f'.
So, the issue is I cannot figure out how to, on one hand read only the *.txt files in, while, on the other, save them as *.dta files, while preserving the name represented by the *.
Any ideas?
Thanks, in advance,
Ben
Ben Hoen
Staff Research Associate
Lawrence Berkeley National Laboratory
Office: 845-758-1896
Cell: 718-812-7589
[email protected]
Fancy new digs!
I am trying to execute a look that pulls in all *.txt files in a folder and then saves each one in another folder as a *.dta file. I am having trouble with the code.
This is what I have (more or less):
**** start ado****
cd "B:\OtherDatabase\folderA"
local files : dir . files "*.txt"
foreach f of local files {
insheet using "`f'", delim("|") names clear //pulls in the .txt file
* create a bunch of new variables, rename variables etc...
cd "B:\OtherDatabase\folderB" //changes to a new folder
save "`f'", replace //saves the file - but in this case, saves it as a *.txt file
cd "B:\OtherDatabase\folderA" //back to the other folder to read in the next file
}
*
**** end ado *****
Ideally I would be able to have <save "`f'", replace> save a *.dta file but instead it saves a *.txt file because that is what is stored in `f'.
So, the issue is I cannot figure out how to, on one hand read only the *.txt files in, while, on the other, save them as *.dta files, while preserving the name represented by the *.
Any ideas?
Thanks, in advance,
Ben
Ben Hoen
Staff Research Associate
Lawrence Berkeley National Laboratory
Office: 845-758-1896
Cell: 718-812-7589
[email protected]
Comment