Statalist The Stata Listserver

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

RE : RE : st: Loop with forvalues ..

From   <>
To   <>
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 :
[] De la part de Svend Juul
Envoyé : 07 November 2006 08:50
À :
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 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

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index