Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Oliver Jones <ojones@wiwi.uni-bielefeld.de> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: FW: nested local |
Date | Fri, 01 Apr 2011 15:13:37 +0200 |
Or maybe something more easy using describe to get your varlist: clear set obs 10 * create 5 variables forval i = 1/5 { gen x`i' = `i' } * create the varlist des x*, varlist foreach var of varlist `r(varlist)' { replace `var' = 9 } list, tab Best Oliver Am 01.04.2011 14:36, schrieb Francesco Fasani:
Hi, My question is the following: I´m trying to run a loop with a local that contains a local and I don´t manage to make it work. I wrote a simplified version below. Basically, it stops at summarize where instaed of summarizeng the variable TR_democr_y_y1 (as I would like it to do) it stops and says that "TR_democr_y_y is an ambiguous abbreviation (because there are five variable called in that way in my dataset: TR_democr_y_y1 ... TR_democr_y_y5. local variables TR_democr_y_y`j' foreach var of local variables { forvalues j=1(1)5 { display `j' di "TR_democr_y_y`j'" su TR_democr_y_y`j' su `var' } } I know I coudl just rewrite the loop as I did below and it woudl work. But the loop I am trying to run is fairly more complex and cannot be written in the version below. local variables TR_democr_y_y foreach var of local variables { forvalues j=1(1)5 { display `j' di "TR_democr_y_y`j'" su TR_democr_y_y`j' su `var'`j' } } Thanks! Francesco Fasani Institute for Economic Analysis (IAE-CSIC) and Barcelona GSE (Graduate School of Economics) Campus UAB 08193 Bellaterra, Barcelona Spain phone: +34 93 592 9779 webpage: http://www.iae.csic.es/investigadorPersonalAbout.php?idinvestigador=90&lang=ing <http://www.iae.csic.es/investigadorPersonalAbout.php?idinvestigador=90&lang=ing>
-- Universität Bielefeld Fakultät für Wirtschaftswissenschaften Lehrstuhl für Ökonometrie und Statistik - - - Bielefeld University Faculty of Business Administration and Economics Chair of Econometrics and Statistics - - - Raum / room: V9-110 Tel / phone: +49 (0)521 106 4871 -- * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/