Announcement

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

  • How to generate mean gender wage gap within occupation? [attempted with no luck]

    I have a set of data sort of like:
    Sex WeekWage Occupation
    0 823 Fishing
    1 917 Hunting
    0 426 Officeing
    What I want to do, is generate another variable, `gap', that is the mean(WeekWage) if sex == 1 - mean(WeekWage) if sex ==0 for every occupation.

    So, here is what I tried:

    Code:
    by occupation, sort: egen gap = mean(WeekWage) if sex == 1 - mean(WeekWage) if sex ==0
    And the error I get is:
    Code:
    unknown function mean()

  • #2
    This is some way from correct syntax, although it takes some experience and understanding of Stata to see that.

    In essence you must use, and can only use, an egen function just once in any egen call. mean() here is the egen function in question.

    So why doesn't egen appear to recognise its own function? I think this follows from the same logic. Once the parser has seen one egen function no other egen function call makes sense; only a call to a general Stata function might make sense and there is no general Stata function mean().

    Also, and this is more general, sex can never be 0 and also 1 in the same observations, which is what your syntax implies.

    So far, so negative, but what you want is not too difficult when you think Stata's way.

    You can get wages conditional on each sex and occupation combination. But you want them to be in the same observations; otherwise subtraction is at best difficult and at worst impossible.

    Here's one way to do it:


    Code:
    by occupation, sort: egen wage1 = mean(WeekWage / (sex == 1))
    by occupation, sort: egen wage0 = mean(WeekWage / (sex == 0))
    gen gap = wage1 - wage0 
    egen tag = tag(occupation) 
    tabdisp occupation if tag, c(wage1 wage0 gap)
    For much more on why that works, and other ways to do it, see http://www.stata-journal.com/sjpdf.h...iclenum=dm0055

    Comment


    • #3
      Assuming you have one observation per Occupation-Sex combination:
      Code:
      reshape wide WeekWage, j(Sex) i(Occupation)
      generate occ_gap=WeekWage1-WeekWage0
      Best, Sergiy

      Comment


      • #4
        John:
        why not changing your approach altogether and switch to -regress- with interactions?:
        Code:
        regress WeekWage i.Sex##i.Occupation
        PS: crossed in the cyberspace with Nick's and Sergiy's replies.
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          Sergiy: That assumption matches the example in #1 but doesn't seem plausible otherwise.

          Comment


          • #6
            Hello everyone,

            I have a dataset similar to John Swiss. I want to estimate the gender gap between professors.

            I constructed my own database and I want to ask you what's the best way to generate simple weights.

            Thanks

            Enrique

            Comment


            • #7
              Hello everyone, Nick's syntax is very useful! I tried to use and add weights, but I think the command doesnt allow it. Am I overlooking something? Thank you.

              Comment


              • #8
                The commands that Nick Cox used do not allow weights; why don't you explain what you are trying to do and what your data look like (please read the FAQ) and maybe someone can come up with an alternative route

                Comment


                • #9
                  Although commands exist otherwise any weighted mean can be obtained from the total of weight * value divided by the total of value. That is three steps with egen .

                  Comment


                  • #10
                    I think Nick means total of weight * value divided by the total of weight. It's still three steps with egen.

                    Comment

                    Working...
                    X