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.
Percentage change in X variable instead of one-unit changeHi all I am running a fixed effects model with independent variable, TotalFundingADA, and dependent…
Difference between reg vce cluster (id) AND reg robust cluster (id)Hello everyone, I am using panel data and running a model with the Least Squares Dummy Variables Mo…
Help for organising dataHi there I have monthly data of many users and of their behaviour. How can I create groups of peopl…
regex expression, extract the number from stringHi, dear all I want to extact all numbers from the string. I want to use the Lookahead and Lookbehin…
How to generate 2 yaxis graph with 2 xaxis group with SD?I have the information here, on the table weeks ISpre A1M B2M sdis sdam sdbm group hiISpre lo…
Subscribe to:
Post Comments (Atom)
0 Response to Sum variables without loosing the remaining variables from the dataset.
Post a Comment