Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating "total number of births by sex", using dummies for sex

    Dear All,

    I would like to create a variable for total number of male birth and total number of female birhts.

    In this data set, females are coded as 2 while males are coded as 1.

    I would like to create a variable, let's say X, that indicates the total number of female births.

    For example, X should be 1 for caseid 010110004 02; and 0 for caseid 010110011 02.

    Thank you in advance.




    Click image for larger version

Name:	stata.png
Views:	1
Size:	10.8 KB
ID:	1604825

  • #2
    Cansu:
    do you mean something along the following lines?
    Code:
    . set obs 4
    number of observations (_N) was 0, now 4
    
    . g id=_n
    
    . g gender=0 in 1/3
    
    . replace gender=1 if gender==.
    
    
    . label define gender 0 "Female" 1 "Male"
    
    . label val gender gender
    
    . bysort gender: egen wanted=count(gender)
    
    . list
    
         +----------------------+
         | id   gender   wanted |
         |----------------------|
      1. |  1   Female        3 |
      2. |  2   Female        3 |
      3. |  3   Female        3 |
      4. |  4     Male        1 |
         +----------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Install the package -egenmore- (type from within Stata -findit egenmore- and follow the instructions to install) and then try something like

      Code:
      egen femalebirths = rcount(B4_*), cond(@==2)
      If it does not work, post a sample of yourdata using -dataex-.

      Comment


      • #4
        Originally posted by Carlo Lazzaro View Post
        Cansu:
        do you mean something along the following lines?
        Code:
        . set obs 4
        number of observations (_N) was 0, now 4
        
        . g id=_n
        
        . g gender=0 in 1/3
        
        . replace gender=1 if gender==.
        
        
        . label define gender 0 "Female" 1 "Male"
        
        . label val gender gender
        
        . bysort gender: egen wanted=count(gender)
        
        . list
        
        +----------------------+
        | id gender wanted |
        |----------------------|
        1. | 1 Female 3 |
        2. | 2 Female 3 |
        3. | 3 Female 3 |
        4. | 4 Male 1 |
        +----------------------+
        
        .
        Dear Carlo Lazzaro,

        Thank you very much for your quick reply.
        What I want is to create total number of female children in the household and the total number of female children and total number of male children as follows:

        I already have ID number and sex of the children in the households. Yet, sex variable is a dummy variable where females are coded as 2 and males are coded as 1.
        When I use "egen totalfemale=rowtotal(sex of child 1 sex of child 2 sex of child 3)" command, it doesnt work aacurately because it fails to distinguish males and females.


        ID number sex of child 1 sex of child2 sex of child3 Total Number of Female Children Total Number of Male Children
        01 Female(coded as 2) Male(coded as1) Female(coded as 2) 2 1
        02 Female(coded as 2) Female(coded as1) Female(coded as 2) 3 0
        03 Male(coded as 1) Male(coded as1) Male(coded as 1) 0 3

        Comment


        • #5
          Originally posted by Joro Kolev View Post
          Install the package -egenmore- (type from within Stata -findit egenmore- and follow the instructions to install) and then try something like

          Code:
          egen femalebirths = rcount(B4_*), cond(@==2)
          If it does not work, post a sample of yourdata using -dataex-.
          It worked! Thank you very much. Using female births and male births, I will compute sex ratio using the following formula: (malebirths/femalebirth)*100

          However, I am also interested in computing sex ratio at LAST BİRTH. For example, the last birth's sex is indicated by B4_01 (01 always indicates the last born child). How can I compute LAST BIRTH's sex ratio?

          Thank you in advance!.
          Last edited by Cansu Oymak; 21 Apr 2021, 04:49.

          Comment


          • #6
            I did not understand any of this "computing sex ratio at LAST BİRTH. For example, the last birth's sex is indicated by B4_01 (01 always indicates the last born child). How can I compute LAST BIRTH's sex ratio?"

            Explain it again with examples like you did the first time in your post #1.

            Originally posted by Cansu Oymak View Post

            It worked! Thank you very much. Using female births and male births, I will compute sex ratio using the following formula: (malebirths/femalebirth)*100

            However, I am also interested in computing sex ratio at LAST BİRTH. For example, the last birth's sex is indicated by B4_01 (01 always indicates the last born child). How can I compute LAST BIRTH's sex ratio?

            Thank you in advance!.

            Comment


            • #7
              Originally posted by Joro Kolev View Post
              I did not understand any of this "computing sex ratio at LAST BİRTH. For example, the last birth's sex is indicated by B4_01 (01 always indicates the last born child). How can I compute LAST BIRTH's sex ratio?"

              Explain it again with examples like you did the first time in your post #1.


              Dear Joro Kolev,

              Thank you very much for your response. I can of course explain you with an example.

              As you said previously, I computed female births and male births.

              Then, I computed the total births using the codes as you provided:
              egen femalebirths = rcount(B4_*), cond(@==2)
              egen malebirths = rcount(B4_*), cond(@==1)
              egen totalbirths=rowtotal(femalebirths malebirths)
              After that I comptuted the sex ratio using the following formula : gen sexratio=(malebirths/femalebirths)*100
              Here is what I have:

              "BORD" is the birth order of the child in matter.
              For example;

              The mother whose CASE ID is 2806 7 2 (row 1), has a female child (B4_01) whose birth order is 3 (BORD_01). This mother's second-born child is Male (B4_02) whose birth order is 2 (BORD_02). Again, the mother's oldest child is Female (B4_03) whose birth order is 1 (BORD_03). In other words, we do know who is the youngest child and who is the oldest child.

              In the following article, "A gender preference measure: the sex-ratio at last birth", they compute sex ratio by birth order and they generate sex-ratio at last birth. Here is the table (I attached). In their table, as you can see, the bold ratios indicate last-birth sex ratio.

              In that respect I have 2 questions:

              1) How can I compute sex ratio by birth order? and for last-born child?

              2) How can I compute sibling sex composition?

              Thank you very much in advance!!!
              Click image for larger version

Name:	article.png
Views:	1
Size:	120.4 KB
ID:	1604872

              Click image for larger version

Name:	article2.png
Views:	1
Size:	86.4 KB
ID:	1604873

              Last edited by Cansu Oymak; 21 Apr 2021, 07:03.

              Comment

              Working...
              X