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: Collapse and count


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Collapse and count
Date   Tue, 19 Nov 2013 19:33:43 +0000

Here is a similar example

sysuse auto
collapse (count) count=mpg (mean) mpg weight , by(rep78)

It follows from the help that you need to give different variable
names for the second and later statistics based on any variable (-mpg-
above). This is also apparent from the fact that different summary
variables will need different names.

To avoid anomalies if there are missing values, something like this is
more careful:

sysuse auto, clear
gen present = !missing(mpg, weight)
collapse (count) present (mean) mpg weight if present , by(rep78)

Nick
[email protected]


On 19 November 2013 19:23, Eric M. Uslaner <[email protected]> wrote:
> I want to collapse a data set and obtain N's for each country in the data set.  I have looked at the manual and online help for collapse, groups, etc. and can't find an answer to this question.
>
> Let's say I want variables X1 X2:
>
> Collapse (mean) X1 X2, by(country)
>
> Gives me what I want except for the N for each country
>
> Collapse (count) X1 X2,by(country)
>
> Just gives me the country Ns without names of countries.
>
> (Sorry for the leading caps, can't get Outlook to use lower case).
>
> What I want is:
>
> Country X1mean X2mean N  where N is for each country
>
*
*   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