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

st: RE: RE: RE: data managment [correction]


From   asad <gunnuox@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: RE: RE: data managment [correction]
Date   Wed, 10 Jul 2002 02:23:13 -0700 (PDT)

Dear Nick:
Thanks again for your insights. In general, it works
but with little correction to your suggestion
commands.

You suggested the following:

bysort hhold (id) : gen S_age = Age[S_id] 
bysort hhold S_id : egen meanS_age = mean(S_age) 
by hhold S_id : egen nS = count(S_id) if S_id < . 
*for husbands
bysort hhold (nS) : gen Sn_age = meanS_age[2] if _n==1

*for wives
by hhold : replace Sn_age = meanS_age[1] if S_age==. &
S_id < . 	

The above doesn't work for the following given the way
S_age is defined:

hhold	id	S_id	Age	S_age
23	2	1	30	35
23	1	2	35	30
23	4	.	65	.
23	3	.	3	.
45	2	1	50	40
45	1	2	40	50
45	6	2	30	50
45	8	.	5	.
45	5	.	5	.
45	4	.	8	.
45	7	.	2	.
45	3	.	12	.

Hence, instead of S_age, if we use the actual age i.e.
"Age" (and also adjusting the "if" constraint in the
last command line), the following works:

bysort hhold S_id: egen meanS_age = mean(Age) if
S_id~=.
by hhold S_id : egen nS = count(S_id) if S_id < . 

*for husbands:
bysort hhold (nS): gen Sn_age = meanS_age[2] if _n==1	

*for wives:
by hhold: replace Sn_age = meanS_age[1] if Sn_age==. &
S_id<. 	

Hence we get,

hhold	id	S_id	meanS_age	nS	Sn_age
23	2	1	30	1	35
23	1	2	35	1	30
23	4	.	.	.	.
23	3	.	.	.	.
45	2	1	50	1	35
45	1	2	35	2	50
45	6	2	35	2	50
45	8	.	.	.	.
45	5	.	.	.	.
45	4	.	.	.	.
45	7	.	.	.	.
45	3	.	.	.	.

But as you rightly note, this works only where we have
at most one married man. Since multi-family household
(with & without polygamy) is very common in my data (&
in developing countries), i am currently trying to get
around this problem.

Thanks again. -Asad.

The last bit of my previous posting needs revision: 

> bysort hhold (nS) : gen S_age = meanS_age[3 - _n] 

Should be 

bysort hhold (nS) : gen S_age = meanS_age[2] if _n ==
1 

That's the husbands. 

by hhold : replace S_age = meanS_age[1] if S_age == .
& S_id < . 

That's the wives. 

Nick 
n.j.cox@d... 



__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index