Statalist The Stata Listserver


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

RE: st: Adding two variables


From   "Nuno Soares" <[email protected]>
To   <[email protected]>
Subject   RE: st: Adding two variables
Date   Sat, 16 Sep 2006 10:44:04 +0100

Thanks a lot Ronnie! 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ronnie Babigumira
Sent: 16 September 2006 10:37
To: [email protected]
Subject: Re: st: Adding two variables

Is this what you want
        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          .

.egen ret2 = rowtotal(ret dlret)
.clist, noobs

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

- help egen - says that

rowtotal(varlist)
             may not be combined with by.  It creates the (row) sum of the
variables in varlist, treating missing as 0.









Nuno Soares wrote:
> 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/
> 
*
*   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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index