Announcement

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

  • Creating a count variable for data with many observations per year/country

    Hello everyone,

    I am having some trouble with a data set, which shows mass demonstrations in the last 30 years. The way the data is set up, is that there is an observation for each protest (so for example there are 7 observations of protests in Canada in 1990). If there are no mass demonstrations in a country in a year it is also coded but then the variable "protest" is just coded 0 instead of the value 1, which all of the observations with protests have.

    What I want to do is make a count-variable that measures how many protests there have been for each year in each countries, and then do a command where I am only left with one observation per country per year, creating panel data.

    Ideally I would like to have a count-variable for two different measures of mass protest, which are both dummys (protest100 and protest1000)

    I hope I have made myself reasonably clear.

  • #2
    Rune:
    welcome to this forum.
    I would take a look at -duplicate- entry in Stata .pdf manual.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3

      Code:
      collapse (sum) protest* , by(country year)
      will ignore the 0s and sum the 1s and reduce the dataset. Strictly, it sums the 0s and the 1s, but naturally adding 0 makes no difference to any sum.

      Comment


      • #4
        Thank you both very much! I felt like I almost had it with the dup-command, but Nick's code solved it a bit faster.

        Comment


        • #5
          Well, duplicates is my code too... in a sense.

          Comment

          Working...
          X