Creating a variable dependent on circumstances over three periods

I am trying a create a variable with a kind of complicated argumentation. Essentially, the variable will say the tax rate the individual is paying, but what decides the tax rate changes like this:

In TIME = 1, the individuals with income above 450.000 pays 50% in taxes, while those below pay 25% (See the dummy ABOVE or INCOME)

In TIME = 2, everyone pays only 25% in taxes.

In TIME = 3, those in GROUP = 1, pays 25%, while GROUP = 2 pays 50%.

This is my data:

structure(list(ID = c(1, 1, 1, 2, 2, 2), TIME = c(1, 2, 3, 1, 
2, 3), GROUP = c(2, 2, 2, 1, 1, 1), INCOME = c(419295.47, 428499.91, 
403197.03, 1286735.3, 1390325.1, 1359411), HIGH = c(0, 0, 0, 
1, 1, 1), ABOVE = c(0, 0, 0, 1, 1, 1)), row.names = c(NA, -6L
), class = c("tbl_df", "tbl", "data.frame"))

Thanks!

library(tidyverse)
mydata %>% 
  mutate(TAXRATE = case_when(
    TIME == 1 & INCOME > 450000 ~ 50,
    TIME == 1 & INCOME <= 450000 ~ 25,
    TIME == 2 ~ 25,
    TIME == 3 & GROUP == 1 ~ 25,
    TIME == 3 & GROUP == 2 ~ 50,
  ))

1 Like

Thank you so much for helping me!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.