Hello:
I am trying to work with the following data set, and build rules for flagging based on if conditions are met. Hoping for assistance.
Each id is a single case that occurs during a specific duration as indicated by the timestamps in date.
I would probably run this with a bysort in front of the ultimate code, as I want to ensure cases are sorted by id and date.
I would like to ultimately know if the final conditions occurred during each case id, sorted by date.
(We could generate a new variable, say final, that marks whether the final conditions were ultimately met)
Rules to generate a "Yes" vs. "No" in the final varlist are:
1. We must encounter 2 or more consecutive occurrences of "1" being in condition to yield a "Yes" in final.
2. If condition starts with consecutive 1s, then has consecutive 0s, then back to consecutive 1s, "Yes" would go in final.
3. If condition is always with 1s and never gets to a 0, then "No" would go in final.
4. If condition starts with 1s, then changes to 0s for the remaining duration, then "No" would go in final.
Overall, having the variable final is optional, if you have a better way of flagging if the conditions are met for a given id. I just suggested that as I don't know any other ways.
Please assist with suggestions as to how to work with conditions and rules like this in general and thanks!
I am trying to work with the following data set, and build rules for flagging based on if conditions are met. Hoping for assistance.
Each id is a single case that occurs during a specific duration as indicated by the timestamps in date.
I would probably run this with a bysort in front of the ultimate code, as I want to ensure cases are sorted by id and date.
I would like to ultimately know if the final conditions occurred during each case id, sorted by date.
(We could generate a new variable, say final, that marks whether the final conditions were ultimately met)
Rules to generate a "Yes" vs. "No" in the final varlist are:
1. We must encounter 2 or more consecutive occurrences of "1" being in condition to yield a "Yes" in final.
2. If condition starts with consecutive 1s, then has consecutive 0s, then back to consecutive 1s, "Yes" would go in final.
3. If condition is always with 1s and never gets to a 0, then "No" would go in final.
4. If condition starts with 1s, then changes to 0s for the remaining duration, then "No" would go in final.
Overall, having the variable final is optional, if you have a better way of flagging if the conditions are met for a given id. I just suggested that as I don't know any other ways.
Please assist with suggestions as to how to work with conditions and rules like this in general and thanks!
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float id double date float condition 1 1.893459e+12 0 1 1.8934593e+12 0 1 1.8934596e+12 0 1 1.8934599e+12 0 1 1.8934602e+12 0 2 1.8944604e+12 0 2 1.8944607e+12 0 2 1.894461e+12 1 2 1.8944613e+12 1 2 1.8944616e+12 1 2 1.8944619e+12 0 2 1.8944622e+12 0 3 1.894707e+12 1 3 1.8947073e+12 1 3 1.8947076e+12 1 3 1.8947079e+12 0 3 1.8947082e+12 0 3 1.8947085e+12 0 4 1.9278003e+12 1 4 1.9278006e+12 1 4 1.9278009e+12 1 4 1.9278012e+12 1 4 1.9278015e+12 1 4 1.9278018e+12 1 4 1.9278021e+12 1 5 1.9279008e+12 1 5 1.9279011e+12 1 5 1.9279014e+12 0 5 1.9279017e+12 0 5 1.927902e+12 0 5 1.9279023e+12 1 5 1.9279026e+12 1 end format %tcNN/DD/CCYY_HH:MM date
Comment