Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: RE : RE : st: Loop with forvalues ..


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: RE : RE : st: Loop with forvalues ..
Date   Tue, 7 Nov 2006 10:39:40 -0000

The maximum number of differences as I understand it 
is surely related to the number of variables you 
have, as Svend and others have already pointed out. 

But in general, yes indeed, you can do anything 
you want upstream so long as it is legal. So, 
if the upper limit of a loop is the maximum 
value of some variable, you can go 

su myvar, meanonly 
local max = r(max) 
forval i = 1/`max' { 
	...
} 

or -- cutting out the middle macro -- 

su myvar, meanonly 
forval i = 1/`r(max)' { 
	...
} 

Nick 
[email protected] 

[email protected]
 
> Thank you .. I understand that "forvalues" needs integer.
> 
> Is there another way to do loop using a local macro n which contains a
> integer value
> 
>  like          local n=max(nb_obs)[1]   
> 
> And then use `n' in a loop, ie to go from i=1 to `n'  ?
 
Svend Juul
 
> Alvine wrote:
> 
> Thank you for your help, but the number of measurement is 
> different from
> patient to patient. So I need to get the maximum value of measurement:
> 
> egen max_mes=max(nb_mes)
> 
> And then use
> 
>  forvalues i=1/`max_mes' {
> 
> ...
> ----------------------------------------------
> 
> No; -forvalues- needs a constant. If you know that
> the patient with most measurements has 97 measurements,
> the command is:
>   forvalues i=2/97 {
> 
> For all patients this creates the variables diff2-diff97,
> but for the patient with three measurements, diff4-diff92
> have missing values. And that is how it should be.

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