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]

st: variable to enumerate children panel dataset


From   "Prado De Castro Alfaiate, Jorge" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: variable to enumerate children panel dataset
Date   Fri, 10 Jun 2011 13:19:11 +0000

Dear statalisters,

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.

Any help would be highly appreciated.

Best regards,
Jorge

PhD student,
Department of economics,
University of Essex.



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