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.
Collapse by what?Hi everyone, I have the following database which I describe quickly. Basically it is a escalation o…
One sided meta analysisI have extracted this data from studies of either treatment (group) 1 or 2. I want to run a meta-ana…
Difference in Difference with multiple time periodsDear All, I am working with a cross-sectional pooled dataset with 8,586 individual-level observatio…
Compound double quotes for single quotesDear Statalisters, I'm wondering if there is a possibility like compound double quotes for single q…
Hausman Test producing different resultsI am using panel data and trying to decide between the fixed and random effects models to use. When…
Subscribe to:
Post Comments (Atom)
0 Response to Sum variables without loosing the remaining variables from the dataset.
Post a Comment