Statalist


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

RE: st: Collapse with sum function and missing values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Collapse with sum function and missing values
Date   Wed, 10 Feb 2010 22:25:37 -0000

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/



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