Announcement

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

  • How do I find the average number of times an ID appears in the dataset?

    Good evening, I am very new to Stata, and I have a probably simple doubt.

    I have a dataset of about 400 000 observations, which includes the following variables.
    ID n_of_appearances
    1 2
    1 2
    2 3
    2 3
    2 3
    Is there a way that I can find the average number of times that an ID appears? In this case that would be 2+3=2.5

  • #2
    Code:
    bysort ID: gen count = _N
    egen tag = tag(ID)
    su count if tag

    Comment


    • #3
      That worked perfectly. Thanks a lot.

      Comment

      Working...
      X