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: FW: nested local


From   Francesco Fasani <[email protected]>
To   [email protected]
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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index