I would like to select specific rows in a dataset but I don't know how I can do it.
- I have more than one row per person.
- Rows per persons are ordered by record number
- Every person has a variable A which can be 0 or 1
I would like to generate the variable select.
- Select should be 1 for all records of a person following the record for which the variable A is 1
- Select should be 0 for the records of a person for which the variable A is 1 and for the previous record numbers of that person
- I have more than one row per person.
- Rows per persons are ordered by record number
- Every person has a variable A which can be 0 or 1
I would like to generate the variable select.
- Select should be 1 for all records of a person following the record for which the variable A is 1
- Select should be 0 for the records of a person for which the variable A is 1 and for the previous record numbers of that person
Person | Record number | Variable A | Select |
1 | 1 | 0 | 0 |
1 | 2 | 1 | 0 |
1 | 3 | 0 | 1 |
2 | 1 | 1 | 0 |
2 | 2 | 0 | 1 |
2 | 3 | 0 | 1 |
2 | 4 | 0 | 1 |
3 | 1 | 0 | 0 |
3 | 2 | 0 | 0 |
3 | 3 | 1 | 0 |
3 | 4 | 0 | 1 |
3 | 5 | 0 | 1 |
Comment