Announcement

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

  • Counting variable by group

    Hi,

    I'm trying to count the number of variables per person that have an ID ending in each integer.
    i.e. 10 variables end in 1, 5 in 2, etc...

    I have a variable for the final digit of the ID, AppInt

    This line works to give the correct value per subgroup:
    bysort examiner auy_numeric: count if AppInt==1

    However when trying to generate a variable for this, the value given is just the total number of observations per person:
    bysort examiner auy_numeric: egen Ones = count(AppInt==1)

    Is there a simpler, less clunky way of doing this that actually works?

    TIA.

  • #2
    I think you want to count observations, not variables (else if you mean what you say, I don't understand your question).

    If Appint holds your final digit then you can


    Code:
    tab anyothervariable Appint 
    
    bysort anyothervariable Appint : gen count = _N
    and so on.

    Comment

    Working...
    X