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

st: RE: RE: RE: referencing variables


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: RE: referencing variables
Date   Thu, 9 Jan 2003 18:40:33 -0000

Lee Sieswerda
> 
> In addition to Daniel's suggestion, you probably want to 
> automatically get
> the values of m. Try Nick Cox's -vallist- on SSC. It gives 
> you the values to
> plug into the -foreach- loop. You might have to fiddle with 
> it a bit, but
> something like this will work:
> 
> vallist m
> local val = r(list)
> foreach m of local val  {
> 	gen y = x`m' + 1
> }
> 

Thanks for the plug, but, again, this won't 
work, for two separate reasons, one of which 
applies to Daniel's suggestion: 

1. Within a loop, you can repeatedly -replace- 
the same variable in one or more 
observations. 

You can not repeatedly -generate- the same 
variable (without -drop-ping it in the 
interim, that is), any more than you can 
do this in general. 

Therefore, the device often used is to 
-generate- a variable containing initial 
values _before_ the loop and then 
-replace- _within_ the loop. 

2. More specifically, -vallist- gives
an ordered list of the distinct values 
in a variable. For this to be what Jackie 
wants, her m variable would have to 
be monotonicly increasing. That's true of
her example, but I don't know that it is 
true in general.  

Nick 
[email protected] 
*
*   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