Never mind! I got it with egen newvar = total(var), by(id)
I have version 16.
I have a data set where each ID is entered 10 times, then for 10 weeks answer yes/no (coded as 1/0) question. I need to create a new variable and then populate it with the number of times the id answers yes.
I know I can generate the number of "yes" per id using
total variable, over(id)
I can then:
gen newvar =.
replace newvar = # if id == [id]
doing that 50 time for each of the IDs doesn't seem efficient -- is there a better way to do this?
I have version 16.
I have a data set where each ID is entered 10 times, then for 10 weeks answer yes/no (coded as 1/0) question. I need to create a new variable and then populate it with the number of times the id answers yes.
I know I can generate the number of "yes" per id using
total variable, over(id)
I can then:
gen newvar =.
replace newvar = # if id == [id]
doing that 50 time for each of the IDs doesn't seem efficient -- is there a better way to do this?
Comment