Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Bowser, William (IITA)" <W.Bowser@cgiar.org> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | st: using macro lists |
Date | Sat, 16 Feb 2013 14:09:23 +0000 |
Dear Statalisters: I am trying to map sets of variables from different data sets with (possibly) different names, but the same labels and attributes. I have developed the following code thus far and encountered a syntax error that I can't resolve. /*=========================================================================*/ //extract sublists of non-attached variables from each country data set // /*===========================================================================*/ local country Ghana Mali foreach c of local country { qui ds3 if a1 =="`c'", all(missing(X)) * di "`c'" * di "`r(varlist)'" local `c'list `r(varlist)' // this is the variable list for each country // * di "``c'list'" } foreach c of local country { local `c'lablist foreach v of varlist ``c'list' { local `c'`v': variable label `v' local `c'lablist "``c'lablist' "`c'`v'"" //create list of labels in each country // * di "`c'" * di "`v'`c'" } } /*=============================================================================*/ //Create a list of the intersection of each `country'lablist // /*=============================================================================*/ ***remember to generalize this later *** local labmatch : list Ghanalablist & Malilablist // this works fine ! // local n : word count `labmatch' di "`n'" foreach c of local country { local `c'labmatch :list `c'lablist & labmatch local n`c' : word count ``c'labmatch' } // verify matches // assert `nGhana' == `nMali' local same : list Ghanalabmatch==Malilabmatch // check to make sure the lists have the same labels // di "`same'" I RUN INTO PROBLEMS HERE: foreach c of local country { foreach v of varlist ``c'list' { local inset_`c'`v' : list ``c'`v'' in `labmatch' di `v' if `inset_`c'`v'' == 1 } } The above code seems like it should work to me but Stata gives me a syntax error when I run it. Please, any help would be greatly appreciated. Best, William Bowser, PhD Postdoctoral Fellow-Agricultural Economist, Socio-economics unit Tel: +234 2 7517472 ext. 2290 Mobile: +234 7068142147 Skype: william.bowser * * 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/