Statalist


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

st: Problem with simple descriptive statistics


From   Stata Chris <[email protected]>
To   [email protected]
Subject   st: Problem with simple descriptive statistics
Date   Tue, 7 Jul 2009 08:54:01 -0400

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index