Announcement

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

  • Counting sorted by company and year

    Hello everyone,

    I have a short question about the count function. I want to sort the data based on cusip code and year and then make a variable that gets the value created by the count function if the classification equals to "I". In order to do so I used the following code
    Code:
     bysort cusip8 fyear: egen Ind=count(classification) if classification=="I"
    Code:
    cusipnr fyear classification Ind
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "E"  .
    2 2009 "E"  .
    2 2009 "I" 11
    2 2009 "E"  .
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "I" 11
    2 2009 "I" 11
    As the example shows, for this company in this year, the output variable should get the value of 11. However, if the classification does not have the value "I", it wont get the numeric value that is counted.

    I was wondering how the output variable can be assigned to every entry of the firm of this year and not only to the entries that have the classification of "I".

    Thanks!

    Last edited by Daan Smith; 18 Jul 2018, 06:15.

  • #2
    I would do this

    Code:
     
     bysort cusip8 fyear: egen Independence=total(classification == "I")

    Comment


    • #3
      Thanks for the quick reply, worked out perfectly.

      Comment

      Working...
      X