Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: infiling a series of ASCII files


From   "Sascha O. Becker" <[email protected]>
To   [email protected]
Subject   st: RE: Re: infiling a series of ASCII files
Date   Thu, 17 Jun 2004 18:20:07 +0200

Dear Nick,

thanks for this very elegant solution to the additional twist, the leading zeros in the file names.

My solution to this was less elegant but equally effective:

global mlist "01 02 03 04 05 06 07 08 09 10 11 12"

foreach month of global mlist {
infile using mydict.dct, using(myfile_`year'_`month'.txt) clear
}

Cheers, Sascha

*******

Nick Cox wrote:
There is an extra sting in the problem. The first nine months
are represented by files with month elements 01 ... 09.
But you are supplying 1 ... 9. The leading "0" needs to be supplied.
Here is one way to do it:

forval y = 1999/2002 {
forval m = 1/12 {
local M : di %02.0f `m'
infile using mydict.dct, using(myfile_`y'_`M'.txt) clear
save "$root\Data\myfile_`y'_`M'.dta", replace
}
}

I also used -forval- here for conciseness and made some other
small changes, mostly cosmetic.

Nick
*
* 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