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

Re: st: about deleting variables


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

--- Hailing Zang <[email protected]> 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

Best,
Ricardo.

=====
Ricardo Ovaldia, MS
Statistician 
Oklahoma City, OK

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
*
*   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