Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Egen functions - preserving missing values?


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: Egen functions - preserving missing values?
Date   Thu, 06 Oct 2005 16:56:50 -0400

Why not just two steps:

egen fam_inc = total(income), by(family)
bysort family (income): replace fam_inc=. if income[1]==.

Michael Blasnik
[email protected]


----- Original Message ----- From: "Eric G. Wruck" <[email protected]>
To: <[email protected]>
Sent: Thursday, October 06, 2005 4:32 PM
Subject: Re: st: Egen functions - preserving missing values?



On September 28th, I posted something quite similar entitled "Collapse & Missing Values". A few people chimed in with their thoughts & ideas. Basically, there is not an easy way around this problem. But here is one that I think works:
<snip>
. egen fam_inc = total(income), by(family)
. egen no_miss = total(cond(income==.,1,0)), by(family)
. egen no_nmiss = total(cond(income~=.,1,0)), by(family)
<snip>
. replace fam_inc = . if fam_inc == 0 & no_miss > 0 & no_nmiss == 0
(5 real changes made, 5 to missing)
<snip>
Kind of kludgy, I know. What I'd really like to see Stata at least offer an option on collapse & egen that would not do this, but Nick Cox rather dashed my hopes on that front. But perhaps someone can write a routine that would automate this?

Best of luck,

Eric

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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