Statalist


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

Re: st: RE: dropping observation


From   Tirthankar Chakravarty <[email protected]>
To   [email protected]
Subject   Re: st: RE: dropping observation
Date   Wed, 10 Jun 2009 23:48:14 +0100

<>
Using Nick Cox's -egenmore- package (SSC):

/* Spells */
clear*
// ssc install egenmore, replace
input forecast_no analystID employerID
1                 1            1
2                 1            1
3                 1            1
1                 2            1
2                 2            1
3                 2            2
4                 2            2
1                 3            3
2                 3            4
end
egen nvalsID = nvals(employerID), by(analystID)
drop if nvalsID==1
list, clean
/* end */

T


On Wed, Jun 10, 2009 at 11:39 PM, Howard Lempel<[email protected]> wrote:
> Not sure if this is the most efficient way, but:
>
> ******* Begin example ********
> /*
>  Create a variable with the mean absolute deviation from the mean of employer ID for each analyst.  This will be 0 if the employer ID never changes.
> */
> by analystID: egen Demp = mdev(employerID)
>
> // Drop observations where the employer ID never changed.
> drop if Demp==0
> ****** End Example **********
>
> Hope this helps.
> Howie
>
> Howie Lempel
> Research Assistant
> The Brookings Institution | Economic Studies
>
> 1775 Massachusetts Ave NW | Washington DC 20036
> [email protected] | p: (202) 238-3576
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Stefano Bonini
> Sent: Wednesday, June 10, 2009 6:18 PM
> To: [email protected]
> Subject: st: dropping observation
>
> Hi
> I have a huge panel dataset containing analyst forecasts. Each analyst is associated with an employer. Sometimes analyst change employer. I want to restrict my dataset, dropping the observations of analysts that never change employer. The dataset may look like this
>
> forecast#     analystID   employer ID
> 1                 1            1
> 2                 1            1
> 3                 1            1
>
> 1                 2            1
> 2                 2            1
> 3                 2            2
> 4                 2            2
>
> 1                 3            3
> 2                 3            4
>
> In this case I'd nee to drop all observations by analyst 1 because he never changes employer, while keeping those of analysts 2 and 3.
>
> I really cannot figure out the way to do it as visual inspection is just impossible with over 1.2m obs.
>
> Thanks!
>
> Stefano
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>



-- 
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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