Thanks, it helped
On Mon, Dec 8, 2008 at 1:50 PM, Nick Cox <[email protected]> wrote:
> Martin Weiss already pointed you in the direction of the data management
> FAQs. When I read your first posting, it seemed that the most relevant
> FAQ was
>
> FAQ . . Creating variables recording prop. of the other members of a
> group
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N.
> J. Cox
> 4/05 How do I create variables summarizing for each
> individual properties of the other members of a
> group?
> http://www.stata.com/support/faqs/data/members.html
>
> However, it now seems that you have quite a different data structure
> from that assumed in the FAQ or by previous contributors to the thread.
> No wonder this thread is moving so slowly: without precise information
> at the outset, people can easily just waste their time.
>
> You don't make it clear even now, but I guess from this that sex is
> coded 1 for female and 0 for male. If not, change the code below.
>
> A loop from first principles is
>
> gen boynum = 0
> gen girlnum = 0
>
> forval i = 1/12 {
> replace boynum = boynum + (sexsib`i' == 0) if `i' <= numsib
> replace girlnum = girlnum + (sexsib`i' == 1) if `i' <= numsib
> }
>
> It may be that you can do it with
>
> egen boynum = anycount(sexsib*), values(0)
> egen girlnum = anycount(sexsib*), values(1)
>
> but much depends on what is stored for any siblings beyond -numsib-. If
> sex is missing if there is no such sibling. The -egen- route should
> work.
>
> Nick
> [email protected]
>
> Nirina F
>
> I tried this:
> egen boynum= count(sexsib*==1), by (hhid)
>
> but of course sexsib* came out as invalid name.
> I have variables sexsib1 , sexsib2, .... sexsib12. These are the sex
> of the siblings and the siblings vary from 0 to 12 depending on the
> number of siblings in the household.
> But I have also numsib whcih tells me the number of siblings.
>
> I guess I have to write a loop :
>
> . forvalues t=numsib{
> 2. egen boynum= count(sexsib`t'==1), by(hhid)
> 3. }
> but then I get " invalid syntax
> r(198);" because I have an error in my code
>
> <big snip>
>
> Nirina F
>
>>>> I have a household survey data and would like to construct a
> variable
>>>> that indicates the sex composition of the respondent's siblings.
>>>>
>>>> I have the year of birth and sex of siblings.
>>>>
>>>> Does anyone know how to do this because the number of siblings vary
> by
>>>> respondent and the minimum number of sibling is 0 and maximum is
> 12.
>
> *
> * 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/