Statalist The Stata Listserver


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

RE : RE : st: Loop with forvalues ..


From   <[email protected]>
To   <[email protected]>
Subject   RE : RE : st: Loop with forvalues ..
Date   Tue, 7 Nov 2006 08:58:54 +0100

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'  ?

-----Message d'origine-----
De : [email protected]
[mailto:[email protected]] De la part de Svend Juul
Envoy� : 07 November 2006 08:50
� : [email protected]
Objet : RE : st: Loop with forvalues .. 


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.

Hope this helps
Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology) Vennelyst Boulevard
6 DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [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/


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