Announcement

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

  • Create gender sex ratio



    Hello,

    I have a large population data set consisting of variables age, sex, province & year in China. I want to create a sex ratio of number of males per 100 females for each age, province and year. So for example the sex ratios (number of males /number of females * 100) for all 18 years old in Beijing the year 1982 etc. Since the dataset is very large I cannot do it manually. I’ve been trying to use the egen command but cannot get it to work. Does anyone know how to do that?

    Best,
    Anna

  • #2
    Anna:
    welcome to this forum.
    No example/excerpt of your dataset=poor reply (from my side, at least).
    Please see the FAQ on how to post more effectively. Thanks.
    That said, as far as -year- are concerned (I assume that you want separate ratios for age, province and year):
    Code:
    bysort year: gen wanted=(number of males /number of females*100)
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Let us act as if the sex variable you have not described takes the values 1 for males and 2 for females. Then perhaps the following can be adapted to provide what you want.
      Code:
      sort age province year
      by age province year: egen n_males = total(sex==1)
      by age province year: egen n_females = total(sex==2)
      generate sex_ratio = ( n_mailes / n_females ) * 100

      Comment


      • #4
        Carlo Lazzaro thank you! I will do that for next time

        Comment


        • #5
          William Lisowski Thank you so much!! It worked! )

          Comment

          Working...
          X