Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: Re: Delete companies based on observations


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: RE: Re: Delete companies based on observations
Date   Wed, 13 Nov 2013 15:19:17 +0000

Amy's technique is in fact more general.  There would no point in
keeping observations with missing values. -egen, count()- lets you
count non-missing values. Asking for _N would ignore any missings.

Nick
[email protected]


On 13 November 2013 13:04, Amy Dunbar <[email protected]> wrote:
> Nick's command deletes directly, which is more efficient.  I create a panel variable using the egen function when I work with Compustat data.
>
> bysort cik: egen pdata=count(fyear)
>
> where cik is the company identifier and fyear is based on fiscal year end. Then I delete based on the pdata value that I want in my dataset.
>
> Amy Dunbar
> UConn
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of M@rk
> Sent: Wednesday, November 13, 2013 5:23 AM
> To: [email protected]
> Subject: st: Re: Delete companies based on observations
>
> Dear Nick,
>
> That is indeed what I meant. Thanks for your help! Now I am able to proceed with my research.
>
> Kind Regards,
>
> Mark Krap
>
> -----Oorspronkelijk bericht-----
> From: Nick Cox
> Sent: Wednesday, November 13, 2013 11:08 AM
> To: [email protected]
> Subject: Re: st: Delete companies based on observations
>
> Various errors here:
>
> 1. -drop- doesn't support a -by()- option: if it did, that would be documented.
>
> 2. There is no -count- function in Stata. Perhaps you mean the -count- command. (-egen- supports a -count()- function, here meaning
> (confusingly) an -egen- function, not a Stata function.)
>
> 3. _n only ever refers to observation identifiers in sequence; you want _N.
>
> 4. -comnam[_n]- is the current value of -comnam-, not its frequency of occurrence.
>
> That said,
>
> bysort comnam : drop if _N <= 13
>
> is what you want.
>
> Nick
> [email protected]
>
> Mark Krap
>
>>  I need to delete all companies of which I have equal or less than 13
>> observations. I already tried the following commands, without the
>> desired result.
>>
>> drop if _n<=13, by(comnam)
>>
>> drop if comnam[_n]<=13
>>
>> I assume that the count funtion in Stata can help me to delete these
>> companies, but I do not know how to incorporate this in a command in
>> order to do the deletions.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index