0

I need to add a variable to my dataframe based on work status within a given month and year.

The work status can change for each person every month. Therefore, I want the workstatus that is present for >50% of the year.

However, I can not figure out how to do this. Does anybody have any suggestions?

I have theese variables for each observation:

  • Workstatus (20 different codes for different workstatus)
  • Year (2012-2019)
  • Month of each year

I guess I need to group by each observation, and then condition somehow, so that for the year e.g. 2012, the work status code that is present >50% within this year is the value that is returned.

Thank you so much!

M--
  • 25,431
  • 8
  • 61
  • 93
  • Can you please provide the data and an example of what the data should look like at the end? Please read this for guidance: [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Harrison Jones Mar 06 '23 at 14:49

0 Answers0