Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Adding two variables


From   "Nuno Soares" <ns.mlists@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Adding two variables
Date   Sat, 16 Sep 2006 10:19:40 +0100

Hi everyone,

I have the following return data (_ret_ for returns and _dlret_ for
delisting returns)for several companies (id):

Id	date	ret	dlret
1	jan91	.1	.
1	feb91	.1	.
1	mar91	0	.05
2	jan91	.05	.
2	feb91	.	-.2
3	jan91	.02	.
3	feb91	-.01	.
3	mar91	.03	.
3	apr91	.1	.
(...)

Ie, there can be several combinations of ret and dlret (at a given month):
- dlret only has a value when a company is delisted and at the delisting
period;
- ret has values and dlret has missing values: this occurs during the period
in which a company is listed. The return for the month is ret.
- ret has values and dlret has values: the company is delisted in that month
and so has a return and can have a delisting return. In this case the return
at that month is ret+dlret;
- ret doesn't has values and dlret has values: the return at that month is
dlret;
In SAS, the procedure to take care of all this possibilities ie easy: just
do ret2=sum(ret,dlret), because the sum function in SAS doesn't read missing
values but still yields a result if ony of the arguments is non missing. In
STATA, I've been looking for a similar function, but can't find it. Does
anyone knows of one?
One solution just doing:
. replace dlret=0 if dlret==.
. replace ret=0 if ret==.
. ren ret2=ret+dlret
However, I'm affraid I could be missing observations by doing this.

All the best,

Nuno

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



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