I have a large panel data set. For each id, it has tons of observations on different days (several years, so this is a very large data set). Now I need a variable that is the sum of a given time period for each id.

Thus, I use
Code:
egen newvar = total(total) if inrange(date, mdy(10, 19, 2005), mdy(10, 9, 2006)), by(id)
By definition, I think for each id, it should contains the same value of newvar. But it is not true. WHY?

And this code doesn't give me the desired outcome. It looks likes I bungled this code.