Statalist


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

st: AW: Problem with simple descriptive statistics


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Problem with simple descriptive statistics
Date   Tue, 7 Jul 2009 15:08:06 +0200

<> 



*************
clear*

//18 funds
set obs 18
gen fund=_n

//100 periods
expand 100

bys fund: gen period=_n

//10 asset classe
expand 10
bys fund period: gen assetclassno=_n

//value normally distr.
gen value=rnormal(1000000,10000)

//let`s see
l in 1/20, noo

//get total per fund and period
bys fund period: /* 
 */ egen totalfundassets=total(value)

//get share per period and fund
gen share=value/totalfundassets

//let`s see
l in 1/100,  /* 
 */ noo sepby(period)
*************



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/



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