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.
Related Posts with Sum variables without loosing the remaining variables from the dataset.
Creating a new dummy based on 4 conditionsHello everyone! We are stuck with a problem creating a new dummy variable from a data with many dum…
under contrast effects for interactionsI have a pretty basic question about interpreting the results from using the -contrast- command for …
"invalid name" when presenting p<0.001 instead of p=0.000Dear All, I calculated p-value after using sts test, and I intended to acquire p<0.001 when calcu…
dissolve in shp fileHi, I study on spatial econometrics. I need NUTS-I level shp file for Turkey. I have also NUTS-II a…
heteroskedasticity in dynamic panelI am working on a Dynamic Panel Model in Stata, i tested for the serial correlation and the heterosk…
Subscribe to:
Post Comments (Atom)
0 Response to Sum variables without loosing the remaining variables from the dataset.
Post a Comment