Good morning,

I have the following variables in the data set: country_code, year, grid_cell (gid), latitude, longtitude and actors (actor_id). I would like to create a new variable adding up the number of actors by grid cell and year. I do it in the following way:

bysort year gid actor_id: gen nactors = _n
keep if nactors == 1
collapse (sum) nactors, by(year gid)



When I do it, I obtained a variable, nactors, which is the sum of actors by year and gid, this is what I want. The number of actors by grid cell and year. However, the other variables dissapear (country_code, latitude and longtitude). Is it possible to obtain what I want without loosing the rest of the variables? My last goal is to obtain the data set I got with my code but with each grid cell associated to the corresponding latitude, longtitude and country_code.

Best,

Diego.