Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Panel Data Programing issues with apologies


From   philippe van kerm <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: Panel Data Programing issues with apologies
Date   Thu, 24 Apr 2008 12:04:14 +0200

> -----Message d'origine-----
> De : [email protected] [mailto:owner-
> [email protected]] De la part de Jeremy Page
> Envoy� : jeudi 24 avril 2008 8:11
> � : [email protected]
> Objet : st: Panel Data Programing issues with apologies
>
> Dear Statalist,

<SNIP>

> I am working with a panel data set which has identifiers by
> household
> (hhid) and individual (id).  I am trying to get information about
> the
> mothers education, which is located in the parents row, into
> children's row.   I figured out how to do this as long as there is
> only one mother in each household.  The problem is there are some
> households with more than one mother per household.  "momid"
> indicates
> which id is the mother in the household and is a number between 3
> and
> 19
>
> hhid   id     edu     momid     (Want mom edu)
>   1      1      4            0                  .
>   1      2      0            0                   .
>   1      3      6            5                  3
>   1      4      8            5                  3
>   1      5      3            0                  .
>   1      6      2            3                  6
>   1      7      4            3                  6

In this particular example, where 'id' is consecutively numbered 1,2,3.. within each household, there is an easy solution:

   bys hhid (id): gen momedu = edu[momid] if momid>0

This works whenever 'id' is equal to _n (within each 'hhid') after you sort on hhid id.


Now, in a more general case, where 'id' may not be related to '_n', I believe that it is easier to "merge the dataset on itself":

preserve
 // generate a file of 'mothers'
 tempfile a
 keep hhid id edu
 rename id momid
 rename edu momedu
 sort hhid momid
 save `a' , replace
restore
// then merge the mothers to the children
sort hhid momid
merge hhid momid using `a' , nokeep uniqusing
sort hhid id
drop _merge

I would be curious to see a way to do it with explicit subscripting, however.

I hope this helps

Philippe




**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept 
**********************************************************************



*
*   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