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

st: RE: automatically creating variables names


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: automatically creating variables names
Date   Mon, 2 May 2005 17:38:37 -0500

Try - foreach x of varlist $indvar { -

This seems to work:

sysuse auto, clear
global indvar mpg-trunk   turn -fore
foreach x of varlist $indvar {
		global pbetas $pbetas `x'1
}
 macro list pbetas


 
. sysuse auto, clear
(1978 Automobile Data)

. global indvar mpg-trunk   turn -fore

. foreach x of varlist $indvar {
  2.                 global pbetas $pbetas `x'1
  3. }

.  macro list pbetas
pbetas:         mpg1 rep781 headroom1 trunk1 turn1 displacement1 gear_ratio1
foreign1


Scott


> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Maria Montez
> Sent: Monday, May 02, 2005 5:29 PM
> To: [email protected]
> Subject: st: automatically creating variables names
> 
> Hi!
> 
> On my simulation I need to create a second set of variables names because
> I'm running two part models. I'm using the following commands, which are
> supposed to append a one at the end of each variable name:
> 
> global indvar Dagesex1 Dagesex2 Dagesex4-Dagesex10 ///
> 	x01-x16 x18-x46 adg1-adg14 adg16-adg18 adg20-adg22 ///
> 	adg26-adg34 Drace2-Drace6 prio_7
> 
> foreach x of global indvar {
> 	global pbetas $pbetas `x'1
> }
> 
> However, the foreach loop does not work because I have lists of variables
> in
> the global indvar, e.g. Dagesex4-Dagesex10.
> 
> Does anyone have a fix for this problem other then having to type each one
> of the variables separately.
> 


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