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: Attaching a set of local macros to a dataset


From   Amadou DIALLO <[email protected]>
To   [email protected]
Subject   st: Attaching a set of local macros to a dataset
Date   Mon, 5 Nov 2012 12:09:36 +0100

Dear stata users,

I am trying to analyze a set of data and am facing the following problem.
I have the following codes:

*** Master do
do builddatabases
do analyzedatabases

*** builddatabases
loc files: dir . files "??pr????.dta"
foreach i of loc files {
   u `i', replace
   // build a new sets of variables based on old ones (the list varies
across datasets.
   // Save the newly created variables in a sets of macros (macro1 macro2, ...)
   sa pr_`i', replace
}

*** analyzedatabases
loc files: dir . files "pr_??pr????.dta"
foreach i of loc files {
   u `i', replace
   foreach j of loc macro1 {
      ...
   }
   foreach j of loc macro2 {
      ...
   }
   ...
}

Now the problem I am having is that the contents of the macros 1, 2,
... varies across datasets and I face the risk of a crash. I know I
can control this with capture. However, I want to find a more
efficient and elegant way to do this.
I thought of char:
char _dta[one] `macro1'
but in the created pr file, I can't find a way to put back the
contents of the char into a local macro. The command:
loc macro1 `_dta[one]
is not working.

How to do this? Or is there any better approach?

Thank you for your time and patience.

Bachir.

-- 

Amadou B. DIALLO, PhD.
Senior Economist, AfDB.
*
*   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