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.
Syntax for funnel plotHello, I'm trying create a funnel plot for a meta-analysis of pre-calculated effect estimates (RR) …
Dummy Variables - New to Stata - Gender pay-gap policyHello, I have recently started learning Stata and have been playing around with data sets. The obse…
install ado filesHello, I am trying to install some ado files which I downloaded from a website in my stata. I read …
How to deal with missings on partner information if the person has no partner?Dear all, I use panel / survey data and in my estimations I include variables like "age of partner"…
stationarity of explanatory variables in time series regressionsI'm finding myself confused and unable to find good answers to what seems to be a simple question: …
Subscribe to:
Post Comments (Atom)
0 Response to Sum variables without loosing the remaining variables from the dataset.
Post a Comment