Statalist


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

st: AW: counting members of groups in unbalanced panel data


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: counting members of groups in unbalanced panel data
Date   Fri, 2 Oct 2009 17:22:06 +0200

<> 

Here is code for your first item requested:


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

inp CompanyID FundID Strategy str10(Date Return)
3021  205  2  "Jan 94"  X
3021  205  2  "Feb 94"  X
3021  405  3  "Jan 94"  X
4671  904  9  "Feb 94"  X
4671  904  5  "Mar 94"  X
4671  154  1  "Mar 94"  X
end

compress
list, noobs  

gen month=monthly(Date, "M19Y")
format month %tmMonth_CCYY
drop Date

//"total number of companies per month"
bys month CompanyID: gen numcomp=_n==1
la var numcomp "# of companies per month"
by month: replace numcomp = sum(numcomp)
by month: replace numcomp = numcomp[_N]
l, sepby(month) noob
*************

With regard to your code, you may want to note that -egen, count()- merely
counts the nonmissing expressions (not the distinct ones), and you may want
to check whether this councides with your intentions...

***
clear*

input x  
1
1
1
.
1
2
3
end

compress

egen myvar=count(x)

list, noobs  
***




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Oliver
Weidenmueller
Gesendet: Freitag, 2. Oktober 2009 16:49
An: [email protected]
Betreff: st: counting members of groups in unbalanced panel data

Hello everyone

I am having troubles figuring out how to in a panel data structure to derive
some descriptives.

In my data

- there are mutliple companies, each having 1 to many funds
- each fund being of one of 11 strategies
- each fund only showing observations for part of the total sample period.

I require

- the total number of companies per month
- the average (median, max) number of funds per company per month
- the average (median, min, max) number of strategies per company per month 

The data format is for example like this:

CompanyID      FundID             Strategy           Date             Return
3021                 205                  2          Jan 94             X
3021                 205                  2          Feb 94             X
3021                 405                  3          Jan 94             X
4671                 904                  9          Feb 94             X
4671                 904                  5          Mar 94             X
4671                 154                  1          Mar 94             X
...

Number of funds per family per month was easy:
by companyid mydate ,sort: egen perfamnrofunds = count(R)

But now I ran into troubles. I would greatly appreciate if anyone could
help.

Thanks in advance,

Best regards,

Oliver 



*
*   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