Statalist The Stata Listserver


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

st: RE: Loop with forvalues ..


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Loop with forvalues ..
Date   Mon, 6 Nov 2006 15:27:54 -0000

Your -forvalues- loop must extend from integer
to integer. 

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

should work. If any -mes`i'- has missing
values then the result will be missing too. 

Nick 
n.j.cox@durham.ac.uk 

alvine.bissery@chu-lyon.fr

> 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

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