Hi all,
The original data set has the first two columns (t, var).
In the third column, I want to get the sum of var every 3 rows, so for t=1-3, sum1=3+4+5=12, for t=4-6, sum1=1+2+8=11. The next column calculates the overlapping sum of var every 3 rows, so for t=1, sum2=3+4+5=12, for t=2, sum2=4+5+1=10.
I choose to sum every 3 rows just for display, it can be quite large like 30. Thus, codes like "gen sum2=var+var[_n+1]+var[_n+2]" are not the best solution here.
How do I generate sum1 and sum2?
Thanks a lot!
The original data set has the first two columns (t, var).
t | var | sum1 | sum2 |
1 | 3 | 12 | 12 |
2 | 4 | 12 | 10 |
3 | 5 | 12 | 8 |
4 | 1 | 11 | 11 |
5 | 2 | 11 | 12 |
6 | 8 | 11 | 19 |
7 | 2 | 12 | 12 |
8 | 9 | 12 | |
9 | 1 | 12 |
I choose to sum every 3 rows just for display, it can be quite large like 30. Thus, codes like "gen sum2=var+var[_n+1]+var[_n+2]" are not the best solution here.
How do I generate sum1 and sum2?
Thanks a lot!
Comment