Statalist The Stata Listserver


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

st: RE: Loop with forvalues ..


From   "Maarten Buis" <M.Buis@fsw.vu.nl>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Loop with forvalues ..
Date   Mon, 6 Nov 2006 16:28:34 +0100

Alvine:
`nb_dos' is a local. Did you specify it before calling the loop (i.e. did you type 
something like -local nb_dos = ...-)? It may be easier to do this by first 
-reshape-ing your data, then create the variable with a lag operator, and then 
-reshape- your data back again to wide format.
HTH,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting adress:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of alvine.bissery@chu-lyon.fr
Sent: maandag 6 november 2006 16:21
To: statalist@hsphsun2.harvard.edu
Subject: st: Loop with forvalues ..

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/

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