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 on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: FW: nested local


From   Francesco Fasani <francesco.fasani@iae.csic.es>
To   statalist@hsphsun2.harvard.edu
Subject   st: FW: nested local
Date   Fri, 01 Apr 2011 14:36:51 +0200

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

 



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index