Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: about deleting variables

From   Ricardo Ovaldia <>
Subject   Re: st: about deleting variables
Date   Tue, 10 Dec 2002 17:47:18 -0800 (PST)

--- Hailing Zang <> wrote:

> I have a question about deleting variables that have
> a certain character. I know if I want to drop, then
> simply use
> .drop if<character>
> But if I want to keep the first observation that has
> that character, what should I do?

Remember that the observations are indexed by _n. That
is, the first observation is _n=1, the second _n=2 and
so on. 

When you sort observations and use the -by- statement
the first observation in each of the possible values
of the "by-variable" is index by _n=1 and so on.

So if you are able to sort your data by the variable,
say x,  you can keep the first occurrence of each of
the x values with the statement:

. by x: keep if _n==1


Ricardo Ovaldia, MS
Oklahoma City, OK

Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index