Hello,
I have this dataset:
I would like to create a new column, let's called it "wanted", which is the sum of column 1 and 2 by actor. However, I would like to count the sum of column1, just if j=2, and the sum of column 2, just if j = 1. In other words, I would like to sum the values of columns 1 and 2 by actor, depending on column j.
I am trying something like this:
But it is not working at all. Any suggestion is more than welcome.
I have this dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte j str1 actor byte(column1 column2) 1 "A" 1 0 2 "B" 0 0 1 "B" 3 0 2 "A" 2 1 1 "C" 4 2 2 "D" 5 3 1 "A" 6 4 2 "B" 1 2 1 "B" 2 0 2 "A" 3 3 1 "C" 4 4 2 "D" 5 1 1 "D" 6 3 2 "B" 7 0 1 "A" 2 10 2 "C" 3 11 1 "E" 4 0 2 "D" 5 0 1 "A" 0 0 2 "B" 0 1 1 "A" 0 2 2 "B" 1 5 1 "E" 2 6 2 "A" 3 2 1 "B" 1 9 2 "E" 0 1 1 "D" 0 1 2 "C" 0 1 end
I am trying something like this:
Code:
bysort actor: egen wanted = total(column1) if j = 2 or total(column2) if j = 1
Comment