Statalist


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

Re: st: Date: Sun, 28 Oct 2007 16:42:05 +0100


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Date: Sun, 28 Oct 2007 16:42:05 +0100
Date   Sun, 28 Oct 2007 16:09:51 +0000 (GMT)

--- Carlo Lazzaro <[email protected]> wrote:
> I have a dataset composed of 30 variables (from patient_1 to
> patient_30). Each variable includes 20 observations (daily cost per
> patient during a 20-day follow-up).
> 
> I would like to create a new variable containing only the 20th day
> observation for each patient. I would figure out something like what
> follows:
> 
> Patient_id   20th_day_observation
> 1		 cost 20th day patient1         
> .			.
> .			.
> .			.
> .			.
> 30		cost 20th day patient30         

*------------------ begin example ---------------
drop _all
set obs 20
gen day = _n
forvalues i = 1/20 {
	gen patient_`i' = exp(.5*_n + .5*invnorm(uniform()))
}

reshape long patient_, i(day) j(id)

preserve
/* if you only want 20th observation*/
sort id day
keep if day == 20
restore

/* if you want to keep all days*/
/* but create a variable that is*/
/* constant within a person and*/
/* contains the 20th observation*/

bys id (day): gen twentiethobs = patient[20]
*----------------- end example -------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten


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

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

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


      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
*
*   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