Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

RE: st: Calculating cumulative value over several observations


From   "Clyde Schechter" <clyde.schechter@einstein.yu.edu>
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 buyer, local(buyers)
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')) -
sum(price*(buyer==`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

Please note new e-mail address: clyde.schechter@einstein.yu.edu

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index