st: constructing sibling sex composition

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

st: constructing sibling sex composition

Nirina F
Hello,
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.

Thank you very much,
Nirian
*
*   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/
Reply | Threaded
Open this post in threaded view
|

st: RE: constructing sibling sex composition

Martin Weiss-5

Line for the server...

You may find the answer here: http://www.stata.com/support/faqs/data/


HTH
Martin


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nirina F
Sent: Sunday, December 07, 2008 9:54 PM
To: [hidden email]
Subject: st: constructing sibling sex composition

Hello,
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.

Thank you very much,
Nirian
*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: constructing sibling sex composition

Nirina F
In reply to this post by Nirina F
Thank you Martin,
you are for example pointing out to this code?

-egen anyfem = max(sex), by(family) -

Thakns,
Nirian

On Sun, Dec 7, 2008 at 4:00 PM, Martin Weiss <[hidden email]> wrote:

>
> Line for the server...
>
> You may find the answer here: http://www.stata.com/support/faqs/data/
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Nirina F
> Sent: Sunday, December 07, 2008 9:54 PM
> To: [hidden email]
> Subject: st: constructing sibling sex composition
>
> Hello,
> 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.
>
> Thank you very much,
> Nirian
> *
> *   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/
>
*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: constructing sibling sex composition

Martin Weiss-5

Line for the server...

This code would give you an indicator variable showing what the highest
value of "sex" is for each family. Provided that in the dummy "sex" the
females are coded as "1" (which in my experience is unusual), you can take
this as a dummy for the presence of at least one female in the family. It
does not give you the number you asked for in the initial post, though...

HTH
Martin


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nirina F
Sent: Sunday, December 07, 2008 10:35 PM
To: [hidden email]
Subject: Re: st: RE: constructing sibling sex composition

Thank you Martin,
you are for example pointing out to this code?

-egen anyfem = max(sex), by(family) -

Thakns,
Nirian

On Sun, Dec 7, 2008 at 4:00 PM, Martin Weiss <[hidden email]> wrote:

>
> Line for the server...
>
> You may find the answer here: http://www.stata.com/support/faqs/data/
>
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Nirina F
> Sent: Sunday, December 07, 2008 9:54 PM
> To: [hidden email]
> Subject: st: constructing sibling sex composition
>
> Hello,
> 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.
>
> Thank you very much,
> Nirian
> *
> *   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/
>
*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: constructing sibling sex composition

Nirina F
In reply to this post by Nirina F
Dear Martin,
I looked but couldn't find which one would work for what I
specifically would like to construct.
Do you mind pointing it to me please?

By the way, what do you mean: line for the server?
Nirina

On Sun, Dec 7, 2008 at 4:41 PM, Martin Weiss <[hidden email]> wrote:

>
> Line for the server...
>
> This code would give you an indicator variable showing what the highest
> value of "sex" is for each family. Provided that in the dummy "sex" the
> females are coded as "1" (which in my experience is unusual), you can take
> this as a dummy for the presence of at least one female in the family. It
> does not give you the number you asked for in the initial post, though...
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Nirina F
> Sent: Sunday, December 07, 2008 10:35 PM
> To: [hidden email]
> Subject: Re: st: RE: constructing sibling sex composition
>
> Thank you Martin,
> you are for example pointing out to this code?
>
> -egen anyfem = max(sex), by(family) -
>
> Thakns,
> Nirian
>
> On Sun, Dec 7, 2008 at 4:00 PM, Martin Weiss <[hidden email]> wrote:
>>
>> Line for the server...
>>
>> You may find the answer here: http://www.stata.com/support/faqs/data/
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Nirina F
>> Sent: Sunday, December 07, 2008 9:54 PM
>> To: [hidden email]
>> Subject: st: constructing sibling sex composition
>>
>> Hello,
>> 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.
>>
>> Thank you very much,
>> Nirian
>> *
>> *   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/
>>
> *
> *   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/
>
*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: constructing sibling sex composition

Martin Weiss-5
Well, you wanted to -count- something, and -egen, count()- sounds like a
good idea to me. It allows -by- as well, so you can count for each family...

HTH
Martin

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nirina F
Sent: Monday, December 08, 2008 12:36 AM
To: [hidden email]
Subject: Re: st: RE: constructing sibling sex composition

Dear Martin,
I looked but couldn't find which one would work for what I
specifically would like to construct.
Do you mind pointing it to me please?

By the way, what do you mean: line for the server?
Nirina

On Sun, Dec 7, 2008 at 4:41 PM, Martin Weiss <[hidden email]> wrote:

>
> Line for the server...
>
> This code would give you an indicator variable showing what the highest
> value of "sex" is for each family. Provided that in the dummy "sex" the
> females are coded as "1" (which in my experience is unusual), you can take
> this as a dummy for the presence of at least one female in the family. It
> does not give you the number you asked for in the initial post, though...
>
> HTH
> Martin
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Nirina F
> Sent: Sunday, December 07, 2008 10:35 PM
> To: [hidden email]
> Subject: Re: st: RE: constructing sibling sex composition
>
> Thank you Martin,
> you are for example pointing out to this code?
>
> -egen anyfem = max(sex), by(family) -
>
> Thakns,
> Nirian
>
> On Sun, Dec 7, 2008 at 4:00 PM, Martin Weiss <[hidden email]> wrote:
>>
>> Line for the server...
>>
>> You may find the answer here: http://www.stata.com/support/faqs/data/
>>
>>
>> HTH
>> Martin
>>
>>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Nirina F
>> Sent: Sunday, December 07, 2008 9:54 PM
>> To: [hidden email]
>> Subject: st: constructing sibling sex composition
>>
>> Hello,
>> 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.
>>
>> Thank you very much,
>> Nirian
>> *
>> *   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/
>>
> *
> *   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/
>
*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: constructing sibling sex composition

Neil Shephard
In reply to this post by Nirina F
Nirina F wrote:
> Dear Martin,
> I looked but couldn't find which one would work for what I
> specifically would like to construct.
> Do you mind pointing it to me please?
>  

Perhaps something like....

local t = 1
foreach x in male female{
  if("`x'" == "female") local t = 2
  egen t_`x' = count(sex) if(sex == `t' & (father != 0 | mother != 0)),
by(family)
  egen n_`x' = mean(t_`x'), by(family)
  bysort family: replace n_`x' = 0 if(n_`x' == .)
  drop t_`x'
}

This will leave you with two variables 'n_male' and 'n_female' which
indicate how many males and females there are in each family
respectively, not including the parents.

There are however a few assumptions in the above code...

1) It assumes that sex is encoded to represent the number of X
chromosomes and individual carries (Males == XY; Females == XX;
Kleinfelters and other forms of trisomy are ignored).

2) It also assumes that you have your data structured in what is known
as LINKAGE whose format is described  at
http://linkage.rockefeller.edu/soft/linkage/   .  Where you have the
following five basic variables that allow you to uniquely reconstruct
the pedigree structure... 'FamilyID'    Uniquely identifies a family
'IndividualID'  Uniquely identifies an individual within the family group
'FatherID' (variable father in above code)   Uniquely identifies the
father within a given family
'MotherID' (variable mother in above code)  Uniquely identifies the
mother within a given family
'Sex' Sex indicator male == 1; female == 2

'Founders' (in the case the parents) of a family do not have
identifiable parents and are therefore given a value of zero for these
two fields.  If you have another way of identifying the parents then you
must exclude them from the 'egen = count()' call, otherwise you will
have them included in the number of males/females in each family.

I can't think of any way of construct _a_ variable that indicates the
sex composition within a family as you originally asked.  If you totaled
up the value of the sex indicators then its too ambiguous, a family with
12 male children would give a total of 12 just as a family of six female
children would, making them indistinguishable.

Obviously if your data is not in this structure you will have to either
coerce it into it or think of an alternative, but the LINKAGE format was
designed specifically for analysing family data (when investigating
genetic linkage of markers to disease phenotypes under parametric models).

Neil


Example....

. list

     +----------------------------------------------------+
     | family   indivi~l   father   mother   sex   t_male |
     |----------------------------------------------------|
  1. |      1          1        0        0     1        . |
  2. |      1          2        0        0     2        . |
  3. |      1          3        1        2     1        . |
  4. |      1          4        1        2     1        . |
  5. |      1          5        1        2     1        . |
     |----------------------------------------------------|
  6. |      1          6        1        2     2        1 |
  7. |      2          1        0        0     1        . |
  8. |      2          2        0        0     2        . |
  9. |      2          3        1        2     2        2 |
 10. |      2          4        1        2     2        2 |
     +----------------------------------------------------+


. local t = 1

. foreach x in male female{
  2.
.   if("`x'" == "female") local t = 2
  3.
.   egen t_`x' = count(sex) if(sex == `t' & (father != 0 | mother !=
0)), by(family)
  4.
.   egen n_`x' = mean(t_`x'), by(family)
  5.
.   bysort family: replace n_`x' = 0 if(n_`x' == .)
  6.
.   drop t_`x'
  7.
. }
(7 missing values generated)
(4 missing values generated)
(4 real changes made)
(7 missing values generated)
(0 real changes made)

. list

     +---------------------------------------------------------------+
     | family   indivi~l   father   mother   sex   n_male   n_female |
     |---------------------------------------------------------------|
  1. |      1          1        0        0     1        3          1 |
  2. |      1          2        0        0     2        3          1 |
  3. |      1          3        1        2     1        3          1 |
  4. |      1          4        1        2     1        3          1 |
  5. |      1          5        1        2     1        3          1 |
     |---------------------------------------------------------------|
  6. |      1          6        1        2     2        3          1 |
  7. |      2          1        0        0     1        0          2 |
  8. |      2          2        0        0     2        0          2 |
  9. |      2          3        1        2     2        0          2 |
 10. |      2          4        1        2     2        0          2 |
     +---------------------------------------------------------------+

--
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein


***********************************************************************
This  message  may  contain  confidential and  privileged  information.
If you  are not the  intended recipient  you should not  disclose, copy
or distribute information in this e-mail or take any action in reliance
on its contents.  To do so is strictly  prohibited and may be unlawful.
Please  inform  the  sender that  this  message has  gone astray before
deleting it.  Thank you.

2008 marks the 60th anniversary of the NHS.  It's an opportunity to pay
tribute to the NHS staff and volunteers who help shape the service, and
celebrate their achievements.

If you work for the NHS  and  would like  an NHSmail  email account, go
to: www.connectingforhealth.nhs.uk/nhsmail
***********************************************************************

*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: constructing sibling sex composition

Nirina F
In reply to this post by Nirina F
Hi Martin,
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

Could you please let me know where I should correct?
Thank you
Nirina







On Mon, Dec 8, 2008 at 3:35 AM, Martin Weiss <[hidden email]> wrote:

> Well, you wanted to -count- something, and -egen, count()- sounds like a
> good idea to me. It allows -by- as well, so you can count for each family...
>
> HTH
> Martin
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Nirina F
> Sent: Monday, December 08, 2008 12:36 AM
> To: [hidden email]
> Subject: Re: st: RE: constructing sibling sex composition
>
> Dear Martin,
> I looked but couldn't find which one would work for what I
> specifically would like to construct.
> Do you mind pointing it to me please?
>
> By the way, what do you mean: line for the server?
> Nirina
>
> On Sun, Dec 7, 2008 at 4:41 PM, Martin Weiss <[hidden email]> wrote:
>>
>> Line for the server...
>>
>> This code would give you an indicator variable showing what the highest
>> value of "sex" is for each family. Provided that in the dummy "sex" the
>> females are coded as "1" (which in my experience is unusual), you can take
>> this as a dummy for the presence of at least one female in the family. It
>> does not give you the number you asked for in the initial post, though...
>>
>> HTH
>> Martin
>>
>>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Nirina F
>> Sent: Sunday, December 07, 2008 10:35 PM
>> To: [hidden email]
>> Subject: Re: st: RE: constructing sibling sex composition
>>
>> Thank you Martin,
>> you are for example pointing out to this code?
>>
>> -egen anyfem = max(sex), by(family) -
>>
>> Thakns,
>> Nirian
>>
>> On Sun, Dec 7, 2008 at 4:00 PM, Martin Weiss <[hidden email]> wrote:
>>>
>>> Line for the server...
>>>
>>> You may find the answer here: http://www.stata.com/support/faqs/data/
>>>
>>>
>>> HTH
>>> Martin
>>>
>>>
>>> -----Original Message-----
>>> From: [hidden email]
>>> [mailto:[hidden email]] On Behalf Of Nirina F
>>> Sent: Sunday, December 07, 2008 9:54 PM
>>> To: [hidden email]
>>> Subject: st: constructing sibling sex composition
>>>
>>> Hello,
>>> 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.
>>>
>>> Thank you very much,
>>> Nirian
>>> *
>>> *   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/
>>>
>> *
>> *   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/
>>
> *
> *   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/
>
*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: constructing sibling sex composition

Martin Weiss-5
As -help forvalues- shows, -forvalues- expects a -range- whereas you provide
it with "numsib"...

HTH
Martin

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Nirina F
Sent: Monday, December 08, 2008 1:23 PM
To: [hidden email]
Subject: Re: st: RE: constructing sibling sex composition

Hi Martin,
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

Could you please let me know where I should correct?
Thank you
Nirina







On Mon, Dec 8, 2008 at 3:35 AM, Martin Weiss <[hidden email]> wrote:
> Well, you wanted to -count- something, and -egen, count()- sounds like a
> good idea to me. It allows -by- as well, so you can count for each
family...

>
> HTH
> Martin
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Nirina F
> Sent: Monday, December 08, 2008 12:36 AM
> To: [hidden email]
> Subject: Re: st: RE: constructing sibling sex composition
>
> Dear Martin,
> I looked but couldn't find which one would work for what I
> specifically would like to construct.
> Do you mind pointing it to me please?
>
> By the way, what do you mean: line for the server?
> Nirina
>
> On Sun, Dec 7, 2008 at 4:41 PM, Martin Weiss <[hidden email]> wrote:
>>
>> Line for the server...
>>
>> This code would give you an indicator variable showing what the highest
>> value of "sex" is for each family. Provided that in the dummy "sex" the
>> females are coded as "1" (which in my experience is unusual), you can
take

>> this as a dummy for the presence of at least one female in the family. It
>> does not give you the number you asked for in the initial post, though...
>>
>> HTH
>> Martin
>>
>>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Nirina F
>> Sent: Sunday, December 07, 2008 10:35 PM
>> To: [hidden email]
>> Subject: Re: st: RE: constructing sibling sex composition
>>
>> Thank you Martin,
>> you are for example pointing out to this code?
>>
>> -egen anyfem = max(sex), by(family) -
>>
>> Thakns,
>> Nirian
>>
>> On Sun, Dec 7, 2008 at 4:00 PM, Martin Weiss <[hidden email]>
wrote:

>>>
>>> Line for the server...
>>>
>>> You may find the answer here: http://www.stata.com/support/faqs/data/
>>>
>>>
>>> HTH
>>> Martin
>>>
>>>
>>> -----Original Message-----
>>> From: [hidden email]
>>> [mailto:[hidden email]] On Behalf Of Nirina F
>>> Sent: Sunday, December 07, 2008 9:54 PM
>>> To: [hidden email]
>>> Subject: st: constructing sibling sex composition
>>>
>>> Hello,
>>> 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.
>>>
>>> Thank you very much,
>>> Nirian
>>> *
>>> *   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/
>>>
>> *
>> *   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/
>>
> *
> *   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/
>
*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: st: RE: constructing sibling sex composition

Nick Cox
In reply to this post by Nirina F
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
[hidden email]

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/
Reply | Threaded
Open this post in threaded view
|

Re: st: RE: constructing sibling sex composition

Nirina F
Thanks, it helped


On Mon, Dec 8, 2008 at 1:50 PM, Nick Cox <[hidden email]> 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
> [hidden email]
>
> 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/