Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: passing macros to dictionary files


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: passing macros to dictionary files
Date   Thu, 24 Apr 2014 00:31:47 +0100

I don't see the need for indirection here. Setting aside complexities
you may need elsewhere

forvalues x=1/3 {
     forvalues myreg=1/6 {
            infix str test 1-244 using 2014030`x'_0`myreg'.csv
            <do something with it>
     }
}

Nick
[email protected]


On 23 April 2014 21:34, Douglas Levy <[email protected]> wrote:
> Hi All,
> I am trying to import a large number of files and aggregate them. My
> strategy was to create <for> loops that generate macros with the
> identifying file names (dates and cash register numbers). However, it
> seems that I can't pass those macros on to the dictionary file, even
> after converting the local macros from the <for> loops to global
> macros that I thought I could pass to the dictionary file.
>
> Here is an example of my code where I am trying to import data for the
> first three days in March for registers 1 to 6:
>
> forvalues x=1/3 {
> local x=string(`x',"%02.0f")
> forvalues myreg=1/6 {
> local myreg=string(`myreg',"%02.0f")
> global date_reg="201403`x'_`myreg'"
> infile using "mydictionary.dct"
> save "mynewfile.dta"
> }
> }
>
> and the dictionary file is:
>
> dictionary using "${date_reg}.csv" {str244 test}
>
> When I run this, I get an error message suggesting that Stata did not
> parse the macro at all:
>
> file ${date_reg}.csv not found
> dictionary invalid
>
> Thoughts? Is it impossible to pass a macro to a dictionary file? If
> so, is there another way to use a single dictionary for many different
> files? Thanks in advance for your advice!
> -Doug
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index