Announcement

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

  • How to count the number of treated firms in unbalanced panel

    Hi Statalist,

    I am trying to count the number of treated firms among those identified by unique ID in the panel data. I tried the following, which generates the number of all observations in the treated group instead of the number of treated firms.
    Could you help me with how to modify the code or suggest any better alternative options in order to check the number of treated firms? Thanks.


    Code:
    bys firmid treated: gen nvals = _n == 1  if treated == 1
    bys firmid: egen count_treated = total(nvals)
    drop nvals
    Last edited by Chul-Kyoo Jung; 09 Mar 2024, 07:19.

  • #2
    bys firmid: egen count_treated = total(nvals)

    There is no logical basis for counting by firm identifier after tagging the first observation of each treated firm, as the count would invariably equal 1 for each treated firm.

    Code:
    bys firmid treated: gen nvals = _n == 1 if treated == 1
    count if nvals==1

    Comment


    • #3
      Andrew Musau Thanks, it makes perfect sense.

      Comment

      Working...
      X