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: variable to enumerate children panel dataset


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: variable to enumerate children panel dataset
Date   Sat, 11 Jun 2011 19:33:50 +0100

This got no replies. Why? I guess you would be better off showing an
example of your data with variable names and detailed explanation of
what is what. Presenting a large chunk of your code, expecting people
to work out what it does and then to work it out why it doesn't do
(all that) you want to do is giving us the wrong kind of information
and the wrong kind of challenge.

Nick

On Fri, Jun 10, 2011 at 2:19 PM, Prado De Castro Alfaiate, Jorge
<[email protected]> wrote:

> I am trying to generate a variable for child enumeration in a family.
>
> I have a panel where the same child appears several times with different ages. This makes things harder.
>
> The code below, which is the closest I could get to my objective, still fails to do what I want.
>
> g chilenum=0
> labe variable chilenum "children enumeration"
> by family: replace chilenum=1 if age<=18 & child==1
> by family: replace chilenum=chilenum[_n-1]+1 if pid[_n]!=pid[_n-1] & age[_n]<=18 & age[_n-1]<=18 & child[_n]==1 & child[_n-1]==1
> by family: replace chilenum=chilenum[_n-1] if pid[_n]==pid[_n-1] & age[_n]<=18 & age[_n-1]<=18 & child[_n]==1 & child[_n-1]==1
> forval i=1/250 {
> by family: replace chilenum=chilenum[_n-`i']+1 if pid[_n]!=pid[_n-`i'] & age[_n]<=18 & age[_n-`i']<=18 & age[_n-`i'+1]>18 & child[_n]==1 & child[_n-`i']==1
> }
> forval i=1/250 {
> by family: replace chilenum=chilenum[_n-`i']+1 if pid[_n]!=pid[_n-`i'] & age[_n]<=18 & age[_n-`i']<=18 & age[_n-`i'+1]>18 & chilenum[_n]==chilenum[_n-`i'] & child[_n]==1 & child[_n-`i']==1
> }
>
>
> Alternatively, if anyone knows how to generate the variables below from a PANEL dataset, that would also be very helpful...
>
> “boy1st” if   First child born is male;
> “girl1st” if First child born is female
> “boy2nd” if Second child born is male
> “girl2nd” if Second child born is female   and so on.
>

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