Hello everybody,
I just started to work with STATA and I need help with my project.
I have a dataset that contains observations of companies between the years 2010 & 2020. I have an ID-Variable, that uniquely identifies every company, a variable "Action" which is filled with the numbers 0 & 1 for 0 if the action didnt took place in this year and 1 if it took place, and the variable year. Due to the fact that the action can happen multiple times a year I dont have one year in one row.
Here you can see an example of my Dataset with company ID's 1234 & 5678:
In the columns "???" I want a new variable that counts the amount of actions for each company for the year X + the next 2 years. In this example it would be for 1234: Sum up actions of 2010 (3) + 2011 (1) + 2012 (2) and write it back in the row of 2010 in "???". The result would be "3" in the rows for 2010. Next for 2011 + 2 Years an so on. Due to the fact that there are multiple rows for a year I cant tell STATA to do it for one row and add the next two, I need to tell it to do it regarding the year within a Company ID and right now I have no clue how I can create such a loop(?).
Is anyone out there with a possible solution?
I just started to work with STATA and I need help with my project.
I have a dataset that contains observations of companies between the years 2010 & 2020. I have an ID-Variable, that uniquely identifies every company, a variable "Action" which is filled with the numbers 0 & 1 for 0 if the action didnt took place in this year and 1 if it took place, and the variable year. Due to the fact that the action can happen multiple times a year I dont have one year in one row.
Here you can see an example of my Dataset with company ID's 1234 & 5678:
| ID | Year | Action | ???? |
| 1234 | 2010 | 0 | |
| 1234 | 2010 | 1 | |
| 1234 | 2010 | 1 | |
| 1234 | 2011 | 0 | |
| 1234 | 2012 | 0 | |
| 1234 | 2012 | 1 | |
| 1234 | … | … | |
| 5678 | 2010 | 0 | |
| 5678 | 2011 | 0 | |
| 5678 | 2011 | 1 | |
| 5678 | 2012 | 1 | |
| 5678 | … | … |
Is anyone out there with a possible solution?

Comment