Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Creating a variable: sum of past 5 years


From   "Mike Kim" <[email protected]>
To   <[email protected]>
Subject   st: Creating a variable: sum of past 5 years
Date   Sat, 7 Apr 2012 14:29:11 -0500

Dear Statalisters,

I would like to create 'sale5yr' which is the sum of total sales for the
past 5 years except its own sale. Can anyone please help me create this
variable? For example,

first row of 'sale5yr'=21+20+19+18+17+16+15+14+13+12=165
second row of 'sale5yr'=22+20+19+18+17+16+15+14+13+12=166
third row of 'sale5yr'=19+18+17+16+15+14+13+12+11=135
......

year	sale	sale5yr
2005	22	165
2005	21	166
2004	20	135
2004	19	136
2003	18	......
2002	17	
2002	16	
2002	15	
2002	14	
2001	13	
2000	12	
1999	11	
1998	10	
1998	9	
1998	8	
1996	7	
1996	6	
1995	5	
1994	4	
1994	3	
1993	2	
1992	1	

Thank you in advance,
Mike.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index