Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Identifying specific observations for which an assert statement is false

    Hi,

    I used the code below to check if all the observations for a particular variable (var1) within the “id” variable are constant. I got the following messages and assume this means that all observations for var1 within the id variable are not constant through the data set. Is there anyway for me to identify which id’ this assertion is false for and/or which rows for which this is so?

    Code:
    bysort id (var1): assert var1[1] == var1[_N]
    37 contradictions in 1,977 by-groups
    assertion is false
    Thank you,
    Karishma

  • #2
    Code:
    bysort id (var1): gen byte flag = (var1[1] != var1[_N])
    You can then -list if flag- or -browse if flag-, or -tab id if flag-, etc.

    Comment


    • #3
      You can flag and inspect those where the assertion if false.

      Code:
      bysort id (var1): gen flag = ( var1[1] == var1[_N])
      list id if flag == 0
      Edit: crossed with #2

      Comment

      Working...
      X