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

# RE: st: Calculating cumulative value over several observations

 From "Clyde Schechter" To statalist@hsphsun2.harvard.edu Subject RE: st: Calculating cumulative value over several observations Date Sat, 11 Dec 2010 10:47:13 -0800

```I think this will get you what you want:

levelsof seller, local(sellers)
local participants: list buyers | sellers
sort market period observation

foreach p of local participants {
by market period (observation): gen M`p' = sum(price*(seller==`p')) -
by market period (observation): gen A`p' = sum(buyer == `p') - sum(seller
== `p')
}

Note:  If your buyers and sellers constitute the integers between 1 and P
for some P, then you don't need to do the -levelsof- commands and you can
replace the foreach loop with a forvalues p = 1/P loop.

By the way, just out of curiosity, if everybody starts out with no money
and no apples, how do they make these trades?

Clyde Schechter, MA MD
Associate Professor of Family & Social Medicine