Statalist


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

Re: st: Collapse with sum function and missing values


From   Michael Mitchell <[email protected]>
To   [email protected]
Subject   Re: st: Collapse with sum function and missing values
Date   Wed, 10 Feb 2010 14:38:56 -0800

Oh, I like that a lot. That is much cleaner than the clunky things I
was thinking.

Thank you Nick!

On 2/10/10, Nick Cox <[email protected]> wrote:
> Something like this?
>
> local i = 1
> foreach v of varlist <whatever> {
> 	local call `call' (sum) `v' (count) nonmiss`i' = `v'
> 	local ++i
> }
>
> collapse `call', by(group)
>
> local i = 1
> quietly foreach v of varlist <whatever> {
> 	replace `v' = . if nonmiss`i' == 0
> 	local ++i
> }
> 	
> Nick
> [email protected]
>
> Michael Mitchell
>
> Thanks all, both for the general thoughts on the underlying rationale
> for this, as well as the practical suggestions. As some noted, I could
> do this...
>
> . collapse (sum) x (count) nonmiss=x, by(group)
> . replace x=. if nonmiss==0
>
> I have about 100 "x" values, and there is no pattern to the names. All
> methods I can think of for ensuring that the "x" values are . when all
> members of the group are . involve either substantial typing or a fair
> amount of programming. Am I overlooking a simple solution for this?
>
>
> *
> *   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index