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.
Fixed Effects With Cross Sectional Data - Inconsistent Standard ErrorsDear all I have a cross-sectional dataset organised in three levels Individuals, nested within... …
arellano-bover/blundell-bondHello people, I have a panel data of 9 firms for a period of 11 years with no missing data. In 2017,…
Request for help- interpreting results post margins.Hello everyone, I am using probit model in Stata 16.1 to identify [dependent var] whether a firm ch…
Free books on Stata programmingHi all, Can anyone recommend free books that provide an introduction to programming with Stata, som…
Systems-GMM: Replicate xtabond2 with xtdpdgmmHi, I try to understand the syntax of xtdpdgmm and would like to replicate my xtabond2 systems-GMM …
Subscribe to:
Post Comments (Atom)
0 Response to Sum variables without loosing the remaining variables from the dataset.
Post a Comment