Hi, I would like to know how I can create a dummy variable called "new_segment" that takes on the value of 1 each time a firm starts operating a new business segment and 0 otherwise. For example: for firm 1 the dummy variable will take on the value of 1 in 2023 that is when it starts operating for the first time in segment "S3". In years 2021 and 2022 the dummy variable takes on 0.
More precicesly, I need to get to this:
Thanks in advance for your suggestions!
Firm id | Segment id | year |
1 | S1 | 2021 |
1 | S2 | 2021 |
1 | S1 | 2022 |
1 | S2 | 2022 |
1 | S1 | 2023 |
1 | S2 | 2023 |
1 | S3 | 2023 |
2… |
Firm id | year | New_segment |
1 | 2021 | 0 |
1 | 2022 | 0 |
1 | 2023 | 1 |
2… |
Comment