Announcement

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

  • Creating variable with sum based on conditions

    Hi all,

    I need to generate a new variable with the sum of the values of a different variable, based on certain conditions. I'll be specific:

    My data is structured as follows:
    Employee Country Year Industry Gender
    A Austria 2000 1 1
    A Austria 2001 1 1
    B Belgium 1999 2 0
    C Belgium 2000 3 1
    D Belgium 2001 4 0
    Gender is a dummy, 0 for male employees, and 1 for female employees.

    I need to generate a variable that adds all of the female employees that worked in each country in a given year. Moreover, the addition should be done by industry. The year varies per country, but it is the same year for all industries in the country. For instance:
    • For Austrian employees in industry 1, my new variable should be the sum of all female employees in the industry 1 in Austria, in 2016.
    • For Belgian employees in industry 2, my new variable should be the sum of all female employees in the industry 2 in Belgium, in 2000.
    • For Belgian employees in industry 3, my new variable should be the sum of all female employees in the industry 3 in Belgium, in 2000.
    • For Belgian employees in industry 4, my new variable should be the sum of all female employees in the industry 4 in Belgium, in 2000.
    What code can I use to obtain this?

    Thank you!

    Kind regards,

    Carla

  • #2
    Code:
    egen wanted = total(gender), by(country industry year)

    Comment

    Working...
    X