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]

st: passing macros to dictionary files


From   Douglas Levy <douglas_levy@post.harvard.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: passing macros to dictionary files
Date   Wed, 23 Apr 2014 16:34:15 -0400

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/


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