Dear Statalist,
I have a bond dataset that's structured as follows:
borrower issuedate maturity
18 Thermal Po~s 23dec2002 5
1st Silicon (~c 19jun2001 7
AB Capital Ma~d 25jul1997 2
AB Lietuvos D~a 25aug2000 3
ABC Roma Bank~d 13mar1997 1
ABN AMRO Bank~V 06apr2001 1
ABN AMRO Bank~V 09may2001 1
ABN AMRO Bank~) 25oct1995 3
AC Internatio~d 30may1996 6
AC Internatio~d 29nov1996 5
AC Internatio~d 16jul1999 6
ACINDAR Indus~A 16jul1993 2
ACINDAR Indus~A 12nov1993 5
ACINDAR Indus~A 14feb1997 7
ADI Cayman Corp 21dec1995 5
AECI Ltd 19jul1991 4
AIG Finance (~d 12apr2001 3
ANACAFE - Aso~e 31aug1993 5
AO IrkutskEne~o 20apr1998 3
AO Moscow Cit~k 19mar1998 3
AO Siberian O~) 15aug1997 3
APP Global Fi~ 17apr1997 5
APP Global Fi~d 04oct1996 5
APP Internati~V 18sep1995 5
APP Internati~V 18sep1995 10
APP Internati~V 28jun1996 3
APP Internati~V 12dec1996 3
...
You won't be able to see this here, but it is sorted by borrower
issuedate mtydate amount (these last two variables not included here).
What I need to do is to create some variables that compute the std
deviation, the mean, and the coefficient of variation of -maturity- BY
BORROWER, and up to the point when a bond was issued. For instance, in
the computation of the mean of maturity, I need to calculate the mean of
the maturities of all bonds issued by that particular borrower up to the
present, without including the maturities of bonds that will be issued
in the future.
I know that I can use egen to compute means and standard deviations (and
then I would just need to divide to get the CV...) but that would
include ALL bonds by the same borrower.
Basically, I need my database to look like this (I did this by hand
using Excel):
borrower closedate maturity mean sdev cvar
18 Thermal Po~s 23-Dec-02 5 5.00 0.00 0.00
1st Silicon (~c 19-Jun-01 7 7.00 0.00 0.00
AB Capital Ma~d 25-Jul-97 2 2.00 0.00 0.00
AB Lietuvos D~a 25-Aug-00 3 3.00 0.00 0.00
ABC Roma Bank~d 13-Mar-97 1 1.00 0.00 0.00
ABN AMRO Bank~V 6-Apr-01 1 1.00 0.00 0.00
ABN AMRO Bank~V 9-May-01 1 1.00 0.00 0.00
ABN AMRO Bank~) 25-Oct-95 3 3.00 0.00 0.00
AC Internatio~d 30-May-96 6 6.00 0.00 0.00
AC Internatio~d 29-Nov-96 5 5.50 0.71 0.13
AC Internatio~d 16-Jul-99 6 5.67 0.58 0.10
ACINDAR Indus~A 16-Jul-93 2 2.00 0.00 0.00
ACINDAR Indus~A 12-Nov-93 5 3.50 2.12 0.61
ACINDAR Indus~A 14-Feb-97 7 4.67 2.52 0.54
ADI Cayman Corp 21-Dec-95 5 5.00 0.00 0.00
AECI Ltd 19-Jul-91 4 4.00 0.00
0.00
AIG Finance (~d 12-Apr-01 3 3.00 0.00 0.00
ANACAFE - Aso~e 31-Aug-93 5 5.00 0.00 0.00
AO IrkutskEne~o 20-Apr-98 3 3.00 0.00 0.00
AO Moscow Cit~k 19-Mar-98 3 3.00 0.00 0.00
AO Siberian O~) 15-Aug-97 3 3.00 0.00 0.00
APP Global Fi~ 17-Apr-97 5 5.00 0.00 0.00
APP Global Fi~d 4-Oct-96 5 5.00 0.00 0.00
APP Internati~V 18-Sep-95 5 5.00 0.00 0.00
APP Internati~V 18-Sep-95 10 7.50 3.54 0.47
APP Internati~V 28-Jun-96 3 6.00 3.61 0.60
APP Internati~V 12-Dec-96 3 5.25 3.30 0.63
So, using -egen-, Stata would generate the same mean and stdev for all
observations for a particular borrower and I do NOT want this.
Notice that whenever there is only ONE bond by borrower, the stdev
should be missing, but I would replace all of these missing by zeros in
the end, since I want all observations to have a nonmissing value and,
for my purposes, I do not differentiate between a zero and a missing
value.
Any thoughts?
Thank you very much.
Best,
Adrian
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/