Hi,

If we collapse data, we essentially create new data set containing averaged values. By creating by group variables, we exhaust memory in creating new variables. Please consider the following data :-

Code:
use http://www.stata-press.com/data/r13/xtline1
xtset person day
xtline calories, overlay
I want to create an overlay line graph for average monthly calorie intake of each person. The code (non-collapse) I've written is as follows:-

Code:
use http://www.stata-press.com/data/r13/xtline1, clear
gen month = month(day)

bys person month: egen monthly_cal = sum(calories)
bys person month: gen dup = _n
keep if dup ==1
drop dup

xtset person month
xtline monthly_cal, overlay
Is there a short, one line command that can give the same results without using collapse and introduction of new variables?

Thanks,
Kedar