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

st: AW: Problem with simple descriptive statistics

From   "Martin Weiss" <>
To   <>
Subject   st: AW: Problem with simple descriptive statistics
Date   Tue, 7 Jul 2009 15:11:05 +0200


On -bysort-, Chris also wants to consult the canonical reference by NJC:


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Stata Chris
Gesendet: Dienstag, 7. Juli 2009 14:54
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

bysort period assetclassno: egen holdings = sum(value)
bysort period:              egen total    = sum(holdings)
bysort period assetclassno:  gen perc     = 100 * holdings/total
keep if period==456
bysort assetclassno: sum perc
egen test = sum(perc)
sum total
sum test

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

Does anyone see where my mistake is?

Many thanks and all best,
*   For searches and help try:

*   For searches and help try:

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