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

st: RE: RE: referencing variables -- no2


From   Daniel M�ller <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: referencing variables -- no2
Date   Thu, 9 Jan 2003 19:38:19 +0100

Sorry, me again. There's another, quicker way, which I've missed (see [P]
foreach).

foreach m in numlist 2 3 6 8 {
	gen y = x`m' + 1
}

Daniel
> 
> foreach m in 2 3 6 8 {
> 	gen y = x`m' + 1
> }
> 
> 
> Greetings,
> Daniel
> 
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]] On Behalf Of 
> > [email protected]
> > Sent: Thursday, January 09, 2003 6:57 PM
> > To: [email protected]
> > Subject: st: referencing variables
> > 
> > 
> > Hello,
> > 
> > I was wondering if anyone can help me on this programming
> > problem.  I have an array of variables, let's say x1-x20, and 
> > I wish to refer to one of them using values in another 
> > variable (let's call it m), in an equation so that I can use 
> > one equation that is different for each observation.  In 
> > other words, if my equation is y = x`m' + 1 and m = 2, then 
> > the equation for that particular observation would be y = x2 
> > + 1.  Here is a partial list of what I'm talking about:
> > 
> > obs    m      equation
> > 
> > 1          2       y = x2 + 1
> > 2          3       y = x3 + 1
> > 3          6       y = x6 + 1
> > 4          8       y = x8 + 1
> > 
> > I don't think using a global or macro variable works because
> > those only take on one value and because the equation is 
> > essentially the model in a non-linear estimation, I don't 
> > think I could use a loop.  I was wondering if there are more 
> > options out there.  Thank you!
> > 
> > 
> > 
> > 
> > Jackie Yuen
> > 
> > 
> > *
> > *   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/
> 
> 


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