Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: St: collapse by _N


From   Chris Parker <cparker.phd2007@london.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: St: collapse by _N
Date   Wed, 20 Oct 2010 12:17:07 +0530

Hi Ric,

You could count the observations in each geocode, then drop if there
are too few observations then collapse.

bysort geocode: gen numobs=_N
drop if numobs < 20
collapse varlist, by(geocode)

Would that work for your purposes?

Chris

Chris Parker

________________________________

PhD Candidate | Management Science & Operations
London Business School | Regent's Park | London NW1 4SA | United Kingdom
Direct line +44 (0)20 7000 8816 | Email cparker.phd2007@london.edu

On Wed, Oct 20, 2010 at 12:05 PM, Eric Uslaner <euslaner@gvpt.umd.edu> wrote:
>
> Greetings,
>
> I have a survey data set with respondents geocoded.  I want to collapse the data set to the geocode level, so the simple command would be:
>
> collapse varlist,by(geocode)
>
> However some geocodes barely have any respondents and any collapsed data would be unreliable.  Is there a straightforward way to collapse only if the number of respondents is > 20 (e.g.)?
>
> Many thanks,
>
> Ric
>
>
>
>
> *
> *   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/
>
> ______________________________________________________________________
>
> This email has been scanned by the MessageLabs Email Security System
> on behalf of the London Business School community.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index