Announcement

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

  • How to calculate number of occurences in the dataset

    Let say my data looks like as I have attached below. There are multiple countries and years are also quite a lot. Each repetition of the year for the country US shows an event that will be counted as 1. In the year 1990, we can say 3 for US and 1 for UK. Similarly, for the year 1991, 2 for UK and 1 for US.
    Year Country
    1990 US
    1990 US
    1990 US
    1990 UK
    1991 UK
    1991 US
    1991 UK


    Can I get a total count in a new column:
    Year Country Total
    1990 US 3
    1990 US 3
    1990 US 3
    1990 UK 1
    1991 UK 2
    1991 US 1
    1991 UK 2
    Last edited by Abdullah Ijaz; 20 Apr 2022, 09:57.

  • #2
    Code:
    bysort Country Year : gen Total = _N

    Comment


    • #3
      Code:
      bysort country year: gen total = _N
      Edit: crossed with #2
      Last edited by Ali Atia; 20 Apr 2022, 10:06.

      Comment


      • #4
        Thanks a lot - Extremely helpful!

        Comment

        Working...
        X