Thanks Nick. I think it's because I'm having a hard time phrasing the question.
Basically, I'm not sure how your code works. I would expect something like this to work:
You can see it's slightly different, in the "replace" code, and "bad==1". And, I do get different results. Using this code, it lists each id after it has found a discrepant value between obs 1 and 2, even if that variable itself isn't discrepant.
I'm just having trouble figuring out how your code works/how Stata interprets it. If you are able to somehow put that into words, that would be great.
Basically, I'm not sure how your code works. I would expect something like this to work:
Code:
clear input id a b c str3 d e f g 1001 1 18 0 cat 0 1 -8 1001 1 18 1 cat 0 1 -8 1002 1 55 0 dog 0 1 -9 1002 1 55 0 dog 0 1 -9 1003 0 42 0 dog 0 0 0 1003 0 42 0 dog 0 0 0 1004 1 36 0 cat 0 1 0 1004 0 36 0 dog 0 1 0 end gen bad = 0 foreach v in a b c d e f g { qui bysort id : replace bad = 1 if (_N == 2) & (`v'[1] != `v'[2]) list id `v' if bad ==1, sepby(id) }
I'm just having trouble figuring out how your code works/how Stata interprets it. If you are able to somehow put that into words, that would be great.
Comment