Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: loop over file names


From   "Rodrigo A. Alfaro" <[email protected]>
To   <[email protected]>
Subject   st: Re: loop over file names
Date   Tue, 6 Jun 2006 12:48:08 -0400

You have to check the format of your files. Suppose they are separated by 
comma and the first line contains the name of the variables

forvalues i=1993/2003 {
    insheet using c:\`i'.txt, comma name
    gen year = `i'
    save c:\`i', replace
    clear
}


----- Original Message ----- 
From: "Wanli Zhao" <[email protected]>
To: <[email protected]>
Sent: Tuesday, June 06, 2006 11:46 AM
Subject: st: loop over file names


I just cannot find the old thread about this.
I have some files called 1993.txt ... 2003.txt.

1. I want to insheet the files by "foreach" or "forvalues".
If I do:
forvalues i of 1993(1)2003 {
insheet using c:\`i'.txt
..
}
It is not working. I also tried other ways and cannot figure how. Invalid
syntax.

2. within each file processing, I need to do "gen year=`i'"

3. after the processing, I need to save the file as ...\`i'.dta.

I am obviously stuck at the "insheet" step but maybe I need to change 2 and
3 also? I appreciate your help. Thanks.

Wanli

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index