Hello,
I have the following dataset of certain incidents occurring in districts across India. The data is in the following format:
I want to convert this data into a panel dataset, with a new variable year that will have values from 2001-10. I also want three new variables that measures the count of the incidents based on their starting year. If you look below it is clear the count_before2001 and count_after2010 will 0 since those years are not being included in the panel. The variable count_before2001 has 3 because in the table above, there are 3 incidents occurring before 2001.
What I am facing a problem in doing is generating the count_between200110 variable. I want this variable to dynamically change based on the starting year variable. As you can see below, this variable takes on the value of 1 when the year becomes 2002, (there is an incident in 2002 in the table above), increases to 2 in 2004 (another incident in 2004), and so on.
I need to replicate this for all the districts in my dataset.
Hope this information is sufficient, if not, I will provide further details on asking.
Thanking the community in advance.
I have the following dataset of certain incidents occurring in districts across India. The data is in the following format:
district | count_totalincidents | startingyear | titleofincident (string) |
AP | 8 | 1995 | abc |
AP | 8 | 1998 | def |
AP | 8 | 2000 | ghi |
AP | 8 | 2002 | jkl |
AP | 8 | 2004 | mno |
AP | 8 | 2007 | pqr |
AP | 8 | 2008 | stu |
AP | 8 | 2009 | vwx |
I want to convert this data into a panel dataset, with a new variable year that will have values from 2001-10. I also want three new variables that measures the count of the incidents based on their starting year. If you look below it is clear the count_before2001 and count_after2010 will 0 since those years are not being included in the panel. The variable count_before2001 has 3 because in the table above, there are 3 incidents occurring before 2001.
What I am facing a problem in doing is generating the count_between200110 variable. I want this variable to dynamically change based on the starting year variable. As you can see below, this variable takes on the value of 1 when the year becomes 2002, (there is an incident in 2002 in the table above), increases to 2 in 2004 (another incident in 2004), and so on.
year | district | count_totalincidents | count_before2001 | count_between200110 | count_after 2010 |
2001 | AP | 8 | 3 | 0 | 0 |
2002 | AP | 8 | 3 | 1 | 0 |
2003 | AP | 8 | 3 | 1 | 0 |
2004 | AP | 8 | 3 | 2 | 0 |
2005 | AP | 8 | 3 | 2 | 0 |
2006 | AP | 8 | 3 | 2 | 0 |
2007 | AP | 8 | 3 | 3 | 0 |
2008 | AP | 8 | 3 | 4 | 0 |
2009 | AP | 8 | 3 | 5 | 0 |
I need to replicate this for all the districts in my dataset.
Hope this information is sufficient, if not, I will provide further details on asking.
Thanking the community in advance.
Comment