Rajesh wrote
The final data set should look like this.
Co month sales meansales X
1 1 100 75 .
1 2 50 75 .
1 3 200 75 125
1 4 15 75 -60
webuse grunfeld,clear
keep company year invest
mvsumm invest, stat(mean) gen(avg2p) win(2) end
by company: replace avg2p=. if _n>2
by company: replace avg2p = sum(avg2p)
by company: gen x = invest-avg2p if _n>2
list
drop avg2p
Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/