Statalist The Stata Listserver


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

st: Loop with forvalues ..


From   <alvine.bissery@chu-lyon.fr>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Loop with forvalues ..
Date   Mon, 6 Nov 2006 16:20:50 +0100

Dear all, 

I have a basic problem, but I don't find the solution:

I have a date set with 1 line per patient, and many measures by patient
(mes1, mes2, mes3, ...). The number of measurement is given by the nb_mes
variable.

id	mes1	mes2	mes3 	mes4	nb_mes
1	 30	 21	 25	 46	 4
2	 26	 24			 2
3	 14	 15	 13		 3


For each patient, I would like to calculate the difference :
 mes2-mes1, mes3-mes, ..., until : mes`nb_mes'-mes1

I've tried this:

forvalues i=2/`nb_dos' {
local im1=`i'-1
gen diff`im1'=mes`i'-mes1
}

Invalid syntax

The problem comes from  forvalues i=2/`nb_dos' 

`nb_dos' is not the good syntax

What should I do ? 

Thank you




*****************************************************
Alvine BISSERY
Ingénieur statisticien 
Service de Biostatistique des Hospices Civils de Lyon 
162 Avenue Lacassagne 
69424 Lyon Cedex 03 - France 
tél: +33 4 72 11 57 55 
fax: +33 4 72 11 51 41 


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index