The basis of my database is violent events. I know in which grid-cell and on which date these events happened. For my analysis I use frequency of violent events in a certain grid-cell, country and year as the dependent variable. To create this frequency variable I collapse
my violent event database and count the number of violent events in a certain grid-cell, in a certain year.
I want to include a value of 0 if there was no violent event in a certain grid-cell in a certain year. However, as my basis is the violent events database, I do not have these observations when I collapse
my data. Is there any way to create a 0 value for observations in years and grid-cells where there was no violent event?
Before I collapse
my dateset it looked like this
+--------------------------+
|Country Year Grid_cell_id |
|--------------------------|
|Benin 2012 365 |
|Benin 2012 365 |
|Benin 2012 367 |
|Benin 2014 365 |
|Benin 2014 365 |
|Benin 2014 365 |
|Benin 2015 240 |
|Benin 2015 240 |
|Kenya 2012 430 |
|Kenya 2012 430 |
|Kenya 2013 467 |
|Kenya 2014 567 |
|Kenya 2014 567 |
|Kenya 2014 567 |
+--------------------------+
Once I collapse
my dataset, it looks like this:
+---------------------------------+
|Country Year Grid_cell_id freq |
|---------------------------------|
|Benin 2012 365 2 |
|Benin 2012 367 1 |
|Benin 2014 365 3 |
|Benin 2015 240 2 |
|Kenya 2012 430 2 |
|Kenya 2013 467 1 |
|Kenya 2014 567 3 |
+---------------------------------+
When I use fillin
to create the 0 frequency value, I only use I only use grid-cell_id and year, but I also want information on the country in which the grid-cell is located. I can easily come to the dataset below with the fillin
function, but how can I preserve the country value, without using it as a fillin
criterion.
+---------------------------------+
|Country Year Grid_cell_id freq |
|---------------------------------|
|Benin 2012 365 2 |
|. 2013 365 0 |
|. 2014 365 3 |
|. 2015 365 0 |
|Benin 2012 367 1 |
|. 2012 367 0 |
|. 2013 367 0 |
|. 2014 367 0 |
|. 2015 367 0 |
+---------------------------------+