Statalist


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

Re: st: keep variables


From   [email protected]
To   [email protected]
Subject   Re: st: keep variables
Date   Tue, 08 Jan 2008 16:16:27 +0100

Thanks a lot  Svend.
it's work fine.
Best,


Quoting Svend Juul <[email protected]>:

Catia wrote:

I have a simple and stupid problem to selection some variables,
but I don't know as to resolve this problem:
I have this dataset

id analt episodi
1 1999 1
1 2002 2
2 2002 1
2 2003 2
2 2003 3
3 2004 1
3 2005 2

I want to selection all the id that analt>2001 & the first
episodi start with ==1, so I want to take id 2 and id 3

id analt episodi
2 2002 1
2 2002 2
3 2004 1
3 2005 2

---------------------------------------------------------

Your question is about keeping observations, not variables.
You can use the -egen min()- function to create a variable
that is constant for each id:

   sort id analt episodi
   by id: egen firstyear = min(analt)
   by id: egen firstepi = min(episodi)
   keep if firstyear>2001 & firstepi==1

The problem is not stupid, it is just a matter of experience.

Svend

__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone:   +45 8942 6090
Mobile:  +45 2634 7796
Email:   [email protected]
__________________________________________

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



Catia Nicodemo



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