<>
On -bysort-, Chris also wants to consult the canonical reference by NJC:
http://www.stata-journal.com/sjpdf.html?articlenum=pr0004
HTH
Martin
-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Stata Chris
Gesendet: Dienstag, 7. Juli 2009 14:54
An: [email protected]
Betreff: st: Problem with simple descriptive statistics
Dear Statalisters,
I have a problem with the bysort syntax (or so I think).
For a set of 18 investment funds, I am trying to figure our for each
period what share of their total assets are held in different asset
classes, using the following code.
The idea was first to compute holdings of each asset class (as
specified by "assetclassno") and period, while summing across all
funds and individual assets. Then I wanted to sum these across all
assetclassno for each period, in order to then compute what share of
the total holdings in that period fell to each assetclassno. And then
I wanted to look at the results for one specific period. Here's the
code:
bysort period assetclassno: egen holdings = sum(value)
bysort period: egen total = sum(holdings)
bysort period assetclassno: gen perc = 100 * holdings/total
preserve
keep if period==456
bysort assetclassno: sum perc
egen test = sum(perc)
sum total
sum test
restore
The problem is that the fractions I get for the different assetclassno
(not all assetclasses are being held in that period though) in period
456 are all way too small, and they don't actually add up to what I'm
being told is the total. Strangely though, the test number is still
100.
Does anyone see where my mistake is?
Many thanks and all best,
Chris
*
* 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/
*
* 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/