last line better as
di "`lowest'" `mean'
Nick
[email protected]
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 06 August 2004 18:38
> To: [email protected]
> Subject: RE: st: Adding new variables to an existing global
> macro listof
> variables.
>
>
> use "C:\XYZ.dta",clear
> global Xlist
>
> foreach var of varlist lntoen lncap lntech lndebt {
> sum `var'
> gen mean`var' = r(mean)
> global Xlist "$Xlist mean`var'"
> }
>
> egen Y=min($Xlist)
>
> But you don't need to use a global for this. Nor
> need you store single values in variables.
>
> use "C:\XYZ.dta",clear
> local mean = .
>
> foreach var of varlist lntoen lncap lntech lndebt {
> su `var', meanonly
> if r(mean) < `mean' {
> local lowest "`var'"
> local mean = r(mean)
> }
> }
>
> di "`var'" `mean'
>
> Nick
> [email protected]
>
> Dev Vencappa
>
> > is there a way to create a global list of variables that
> > starts empty and successively adds new variables to the list
> > as they are created? I am trying to write something like:
> >
> > use "C:\XYZ.dta",clear
> >
> > global Xlist
> >
> > foreach var of varlist lntoen lncap lntech lndebt{
> > sum `var'
> > gen mean`var'=r(mean)
> > global (add the newly created variable mean`var' to $Xlist)
> > }
> >
> > *then take the minimum of all these variables
> > egen Y=min($Xlist)
> >
> > The reason I am trying to use a macro is because I have to
> > create many variables and use the one that has the lowest
> > value. This has to be done within a loop for each of several years.
> >
> > Any alternative approach to mine would be really appreciated.
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/