[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Egen functions - preserving missing values?
Why not just two steps:
egen fam_inc = total(income), by(family)
bysort family (income): replace fam_inc=. if income==.
----- Original Message -----
From: "Eric G. Wruck" <firstname.lastname@example.org>
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:
. 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)
. replace fam_inc = . if fam_inc == 0 & no_miss > 0 & no_nmiss == 0
(5 real changes made, 5 to missing)
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,
* For searches and help try: