I have the following data below with id, result and results-date. I would like to tag by id and date, observations that have at least 2 consecutive values of >=20 and have this be "1" in the new variable. If an observation does not have 2 consecutive values, I would like this tagged "0" . So for example, id 1 in my example dataset below has a 20 and immediately followed by a 20, so in the new variable, id 1 will be tagged a 1. I used the following code below but I am not getting this at all.
[CODE]
egen tag = tag(id resultdate)
egen ngood = total(tag * (result >= 20)) , by(id)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte(id result) int resultdate 1 20 20089 1 20 20211 1 35 20226 1 28 20227 1 33 20241 1 32 20281 2 12 20089 2 11 20211 2 13 20226 2 12 20241 2 12 20270 2 12 20298 3 23 20089 3 25 20211 3 28 20226 4 31 20089 4 12 20211 4 14 20226 4 27 20227 4 10 20241 5 20 20089 5 12 20211 5 13 20226 5 16 20241 end format %tdnn/dd/CCYY resultdate
0 Response to How to find 2 consecutive values for a dataset with repeated observations
Post a Comment