Hello,
I am trying to generate a variable that tracks the number of times a unique event occurred to a specific actor in chronological order. For instance, the number of times Person 001 received traffic citations over the course of several years. The issue I am running into is the unique event "numbers" were randomly assigned in the original data, so when I try the following command:
bysort specific_actor(ticket_number): gen ordered_count_of_citations=sum(traffic_ticket_numb er!=traffic_ticket_number[_n-1])
I'm getting things counted in the (nonsensical) order of the ticket number rather than the order in which they occurred. I've tried to troubleshoot a few different ways, including creating a unique string identifier based on the year of violation and the ticket number but no matter what I do these randomized ticket numbers are mucking things up.
Here is what my data looks like, and a column of what I WANT the data to look like when I'm done (thing_i_want)
Thanks in advance for the help!
I am trying to generate a variable that tracks the number of times a unique event occurred to a specific actor in chronological order. For instance, the number of times Person 001 received traffic citations over the course of several years. The issue I am running into is the unique event "numbers" were randomly assigned in the original data, so when I try the following command:
bysort specific_actor(ticket_number): gen ordered_count_of_citations=sum(traffic_ticket_numb er!=traffic_ticket_number[_n-1])
I'm getting things counted in the (nonsensical) order of the ticket number rather than the order in which they occurred. I've tried to troubleshoot a few different ways, including creating a unique string identifier based on the year of violation and the ticket number but no matter what I do these randomized ticket numbers are mucking things up.
Here is what my data looks like, and a column of what I WANT the data to look like when I'm done (thing_i_want)
specific_actor | violation_year | ticket_number | ordered_count_of_citations | thing_i_want |
001 | 2001 | 78 | 4 | 1 |
001 | 2004 | 63 | 3 | 2 |
001 | 2004 | 63 | 3 | 2 |
001 | 2006 | 21 | 1 | 3 |
001 | 2007 | 22 | 2 | 4 |
002 | 2010 | 88 | 1 | 1 |
002 | 2011 | 89 | 2 | 2 |
003 | 1999 | 54 | 1 | 1 |
003 | 1999 | 93 | 3 | 2 |
003 | 2001 | 84 | 2 | 3 |
Comment