Announcement

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

  • Panel data - count groups

    Hello,
    probably there is a very simple solution to my problem. I am still stuck...
    I have panel data and want to count all the groups that satisfy a certain condition, i.e. a dummy variable ==1. All my groups have a varying number of observations (some have only 3, some have 6, and so on). The dummy variable is time-invariant / does not change over time and remains the same value per group. I would like to know how many individual groups have dummy var == 1 and how many var == 0. Please help me out here, thank you!

  • #2
    Well, since you say that the dummy variable is time-invariant, it's particularly simple:
    Code:
    egen flag = tag(group)
    tab dummy_var if flag

    Comment


    • #3
      Great, thank you very much!

      Comment


      • #4
        I have a question similar to my initial post.

        The code Clyde Schechter provided was just working fine. Now I have the problem that I want to count all groups if a (dummy) variable of each group's second observation is equal to 1. How can I accomplish that?

        Thank you!

        Comment


        • #5
          Code:
           
          bysort panelid (time): gen wanted = myvar[2] == 1 
          su if wanted
          For a balanced panel, this could be easier: e.g.

          Code:
          count if myvar & year == 1982
          for a panel dataset with years 1981...whatever.

          Comment

          Working...
          X