Announcement

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

  • Number of people in a company by gender by the total gender-wise workforce

    I have three variables: company, gender and wf. The variable company takes 20 values (ranging from 1 to 20, each identifying a specific company and having some frequency against each value for men and women working in each company), the variable gender takes two values (1= male, 0=female), the variable wf takes the values 1 and 2 (not in the workforce and in the workforce respectively in a given city) (in case they are in the workforce, they are working in one of these companies).
    I am interested in calculating the difference between number of males in each occupation divided by a constant (57612 = total men in the workforce) and the number of women in each occupation divided by a constant (25312 = total women in the workforce).
    I have tried using the following commands:

    bysort gender: egen totalwp = count(wp) if wp==2
    bysort gender company: egen company_gender= count(company)
    gen company_gender_wp= (company_gender/totalwp)*100 /

    gen company_f_wp= (company_gender/totalwpr)*100 if gender==0
    gen company_m_wp= (company_gender/totalwpr)*100 if gender==1

    These give me a dataset where against each value "1" in the company variable, I have the value "X" for variable company_m_wpr and value "Y" for the variable company_f_wp.
    I want a variable with the values for men and women that i can tabulate against the company variable to look at the number of men/women in each company divided by number of men/women in the workforce.

    Any help would be appreciated
    Last edited by Shantanu Shukla; 26 Jun 2023, 10:10.

  • #2
    When asking for help with code, one should include example data to work with. The best way to do that is by using the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Also, I think a clearer explanation of what you are trying to calculate would be helpful. Looking at the code you show in #1, I suspect it is not giving you what you want. For example, when I see a command to create a variable with a name like totalwp beginning -bysort gender: egen totalwp = ...- I assume you are looking to get a variable that shows the total number of workforce participants in each gender. But that is not what -count(wp) if wp==2- calculates. So I suspect that your existing code needs some revisions. To do that well requires a clear and certain understanding of what is needed.

    Comment


    • #3
      Apologies for confusing you with less information.
      The image attached here is similar to my dataset. I've changed the variable names to match my dataset.
      The total male and female workforce is 5112 and 2113 respectively.
      All of them are employed in some or the other 'company' (the variable company takes numerical values, in the example dataset the values are labelled).
      I want to get a table with the percentage of male (female) members in each company out of total male (female) workforce (for example, if 50 male observations are recorded as working in company 1, I want the figure 50/5112).

      Click image for larger version

Name:	image_31529.png
Views:	1
Size:	157.7 KB
ID:	1718530 Click image for larger version

Name:	image_31530.png
Views:	1
Size:	60.2 KB
ID:	1718531
      Last edited by Shantanu Shukla; 26 Jun 2023, 23:32.

      Comment


      • #4
        Clyde Schechter gave explicit advice in #2

        When asking for help with code, one should include example data to work with. The best way to do that is by using the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.
        which you didn't follow. He's right: screenshots don't give all the information needed here. gender is evidently a numeric variable with value labels male and female (and, just possibly, some missing values and/or other categories).

        Let's suppose gender has value 1 for male and 2 for female. Then you can go

        Code:
        egen males = total(gender == 1), by(company) 
        count if gender == 1 
        gen pc_males = 100 * males / r(N)
        If you are working with that variable henceforth, each company should be counted just once in many calculations, so that for example

        Code:
        egen tag = tag(company) 
        quantile pc_males if tag
        shows the distribution by company whereas

        Code:
        quantile pc_males
        shows the distribution by person.

        Naturally if your values are different you need to modify the code.

        https://journals.sagepub.com/doi/pdf...36867X19830921 recycles old advice, to code (false, true) conditions as (0, 1) variables (which may be true of your variable, but I am guessing otherwise) and to name an indicator by the condition coded 1 (not true of gender).


        Comment

        Working...
        X