Statalist


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

Re: st: RE: Panel Data Programing issues with apologies


From   "Jeremy Page" <miahpage@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Panel Data Programing issues with apologies
Date   Sat, 26 Apr 2008 18:13:16 -0400

Dear Statlist,

Thanks for the help!

Because my id number were numbered consecutively starting at one.  I
was able to use

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

and it worked great.

Best,
Jeremy

On Thu, Apr 24, 2008 at 8:39 AM, n j cox <n.j.cox@durham.ac.uk> wrote:
> The FAQ
>
>  <http://www.stata.com/support/faqs/data/members.html>
>
>  has a section on "7. Mapping from arbitrary identifiers to integers 1 and
> above" which may help here.
>
>  Nick
>  n.j.cox@durham.ac.uk
>
>  philippe van kerm replied to Jeremy Page
>
>  <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.
>
>  *
>  *   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/
>
*
*   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