Hello everybody!
I have the following dataset (reported in the table below) where an Accident can occur (when it occurs, "Accident"=1 / otherwise=0) for each ID throughout the years. What I would like to do is to generate a dummy variable (DUMMY) which takes the value of the Accident variable occurring in the first year of reference (for each ID), and then it keeps and expands that (binary) value thoughout all the remaining years (for each ID).
Here is my (unsuccessful attempt)
bysort Year: egen DUMMY = rowfirst(Accident)
Any help would be very much appreciated.
Thanks.
Kodi
I have the following dataset (reported in the table below) where an Accident can occur (when it occurs, "Accident"=1 / otherwise=0) for each ID throughout the years. What I would like to do is to generate a dummy variable (DUMMY) which takes the value of the Accident variable occurring in the first year of reference (for each ID), and then it keeps and expands that (binary) value thoughout all the remaining years (for each ID).
| ID | Year | Accident | DUMMY |
| 1 | 2001 | 0 | 0 |
| 1 | 2002 | 1 | 0 |
| 2 | 1999 | 1 | 1 |
| 2 | 2000 | 0 | 1 |
| 2 | 2001 | 1 | 1 |
| 3 | 2012 | 0 | 0 |
| 3 | 2013 | 0 | 0 |
| 3 | 2014 | 1 | 0 |
Here is my (unsuccessful attempt)
bysort Year: egen DUMMY = rowfirst(Accident)
Any help would be very much appreciated.
Thanks.
Kodi


Comment