Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: generating parent variable in child level data


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: generating parent variable in child level data
Date   Mon, 8 Nov 2010 11:05:53 +0000

<>

I read Shikha's question as wanting the value of "education_father" or "age_father" only 
for a child's (e.g. son or daughter) records/rows.  If so, Mitch's example could be modified 
to replace these variables with missings  if   relation != "son" | relation != "daughter",  or 
here's another approach with -egen- instead of -levelsof-:

************!
clear
inp hhid   str10(relation)    age    education
1   father      40        8
1   mother    38        3
1   son         18       4
1   son         15       2
1   daughter   12      2
2   father  30  9
2   son     5   2
2   father  32  12
end
**I added some cases to show an example with 
**mutliple parents of same sex in a HH


foreach v in mother father {
 foreach x in age education {
bys hhid: egen `v'_`x'2 = mean(`x')  ///
	if relation=="`v'"
bys hhid: egen `v'_`x' = max(`v'_`x'2)
replace `v'_`x' = .    ///
   if !inlist(relation, "son", "daughter")
drop `v'_`x'2
	}
}
************!

- Eric

__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754



On Nov 7, 2010, at 8:55 PM, Mitch Abdon wrote:

> Hi. Here is one way of doing this:
> 
> gen age_mother=.
> gen age_father=.
> gen educ_mother=.
> gen educ_father=.
> levelsof hhid, local(levels)
> foreach i of local levels{
> 	qui: sum age if relation=="mother" & hhid==`i'
> 	replace age_mother=r(mean) if hhid==`i'
> 
> 	qui: sum age if relation=="father" & hhid==`i'
> 	replace age_father=r(mean) if hhid==`i'
> 
> 	qui: sum education if relation=="mother" & hhid==`i'
> 	replace educ_mother=r(mean) if hhid==`i'
> 
> 	qui: sum education if relation=="father" & hhid==`i'
> 	replace educ_father=r(mean) if hhid==`i'
> }
> 
> if you don't need the lines for 'mother' and 'father' , you can just drop them
> 
> On Mon, Nov 8, 2010 at 9:58 AM, Shikha Sinha <[email protected]> wrote:
>> Dear  all,
>> 
>> I have a household level data set in which each household has father,
>> mother, and child level data as row, something as the following:
>> 
>> hhid   relation    age    education
>> 1        father      40        8
>> 1        mother    38        3
>> 1        son         18       4
>> 1        son         15       2
>> 1        daughter   12      2
>> 
>> I wish to generate parent level variable (age, education)  for every
>> children in the same household. Please suggest.
>> 
>> Thanks,
>> Shikha
>> *
>> *   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/
>> 
> 
> 
> 
> -- 
> Best,
> Mitch
> 
> ------------------------------------------------------------------
> Arnelyn Abdon
> Consultant
> Central and West Asia Department
> Asian Development Bank
> Philippines
> 
> http://statadaily.wordpress.com
> ------------------------------------------------------------------
> 
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index