Statalist The Stata Listserver


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

st: RE: Loop with forvalues ..


From   "Nick Cox" <[email protected]>
To   <[email protected]>
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 
[email protected] 

[email protected]

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