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

st: Re: infiling a series of ASCII files


From   "Oleksandr Talavera, EUV" <talavera@euv-ffo.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: infiling a series of ASCII files
Date   Thu, 17 Jun 2004 16:30:14 +0200

maybe I misunderstood the problem... If all data files have the same
structure, then
in the loop just specify the data file that you want to use...
*****************
foreach year in 1999(1)2002 {;
   foreach month in 1(1)12 {;
   infile using mydict.dct, using myfile_`year'_`month'.txt clear;
   save "$root\Data\myfile_`year'_`month'.dta", replace;
      };
 };
******************
and mydict.dct maybe jus like

********
dictionary {
int a
int b

}
*******

Best,
sasha
----- Original Message ----- 
From: "Sascha O. Becker" <sascha.becker@gmx.de>
To: <statalist@hsphsun2.harvard.edu>
Sent: Thursday, June 17, 2004 3:47 PM
Subject: st: infiling a series of ASCII files


> Dear Stata listers,
>
> I have a series of ASCII files that have names carrying the year and
> month as part of their names:
>
> myfile_1999_01.txt
> myfile_1999_02.txt
> ...
> myfile_2002_12.txt
>
> and want to read them in using one and the same dictionary.
>
> I have a do-file (mydata.do) in which I loop year and month
>
> ***
> foreach year in 1999(1)2002 {;
>     foreach month in 1(1)12 {;
>
> infile using mydict.dct, clear;
> save "$root\Data\myfile_`year'_`month'.dta", replace;
>
>     };
> };
> ***
>
> In order to call the correct ASCII files, I need to adress them in my
> *.dct file (mydata.dct) in the first line.
>
> +++++
>
> Using locals does not work:
>
> dictionary using "myfile`year'_`month'.txt" {
> STUFF
> }
>
> because Stata does not carry them over to the *.dct file.
>
> +++++
>
> So, I thought, I'd use macros and add the following line to the above
loop:
>
> global year "`year'"
> global month "`month'"
>
> and then call them in my *.dct file
>
> 1) dictionary using "myfile_$year_$month.txt"
>
> or
>
> 2) dictionary using "myfile_{$year}_{$month}.txt" {
>
> but this does not work either.
>
> Do you have any suggestions on this?
>
>
> Best regards, Sascha Becker
>
> -- 
>
> Dr. Sascha O. Becker
> Center for Economic Studies
> University of Munich
> Schackstr. 4 - 80539 Munich, Germany
> Tel +49 (89) 2180-6252   http://www.lmu.de
> Fax +49 (89) 39 73 03    sbecker@lmu.de
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index