Re: AW: st: AW: Calculating a (changing) accumulative sum

 From [email protected] To [email protected] Subject Re: AW: st: AW: Calculating a (changing) accumulative sum Date Thu, 14 Jan 2010 18:29:44 +0100

```Dear Martin, your first answer to my question was:
```
```*************
```
help sum()
```*************
```
It was a little short but helpful though! So I tried a little bit myself and surprisingly ;-) came to
```
bysort subject (period) : gen accumcon=sum(con)

```
I was so happy about my own success that I possibly overlooked your recommandation on your longer second answer. This is the explanation for the false "also". Thank you again for your quick responses!
```Best, Ozgur

Martin Weiss schrieb:
```
<>
```I am glad to hear that! BTW, and just out of curiosity: What does "also"
mean here? Is your solution not exactly what I recommended?

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Donnerstag, 14. Januar 2010 18:00
An: [email protected]
Betreff: Re: st: AW: Calculating a (changing) accumulative sum

bysort subject (period) : gen accumcon=sum(con)

also worked! :-)

Thank you very much!

Martin Weiss schrieb:
```
<>
```
Try Nick`s http://www.stata-journal.com/sjpdf.html?articlenum=pr0004 for
further explanations...

*************
clear*
set obs 10
gen byte subject=_n

expand 10
bys subject: gen byte time=_n

gen con=int(runiform()*20)

bys subject (time): gen accumcon=sum(con)

l, sepby(subject) noo
*************

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Donnerstag, 14. Januar 2010 17:49
An: [email protected]
Betreff: st: Calculating a (changing) accumulative sum

```
I have 20 "period"s (i.e., 20 rows) of data for each "subject" i. For each subject i, I would like stata to calculate the accumulative sum of the variable "con" in a new variable "accumcon" in the following way:
```
```
In period 1: accumcon = con[1]. In period 2: accumcon = con[1]+con[2] In period 3: accumcon = con[1]+con[2]+con[3] and so on, for each subject, from period 1 until period 20.
```

```
```
```
```
--
Dr. Özgür Gürerk

Lehrstuhl für Mikroökonomie & Laboratorium für experimentelle Wirtschaftsforschung
(Microeconomics & Laboratory for Experimental Economics)

```
Universität Erfurt, Nordhäuser Str. 63, D-99089 Erfurt
```Tel: +49 361 7374561
Fax: +49 361 7374569
www.uni-erfurt.de/elab
--

*
*   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/
```

• References: