Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Adding new variables to an existing global macrolistof variables.


From   "Dev Vencappa" <[email protected]>
To   <[email protected]>
Subject   RE: st: Adding new variables to an existing global macrolistof variables.
Date   Sun, 08 Aug 2004 13:10:30 +0100

>>
>>
Nick,
 thanks a lot for your useful suggestion. It saves having to create extra variables within the dataset.I have been able to implement what I wanted to. 

Dev

>>> [email protected] 06/08/2004 18:38:21 >>>
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/


This message has been scanned but we cannot guarantee that it and any
attachments are free from viruses or other damaging content: you are
advised to perform your own checks.  Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index