Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[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 <stata.diallo@gmail.com>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index