Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Collapse & Missing Values


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   st: Re: Collapse & Missing Values
Date   Wed, 28 Sep 2005 14:05:26 -0700 (PDT)

Eric,

Here is one way to preserve the missing value.

. bysort date: egen sum = sum(amount)
. replace sum = . if amount==.
(2 real changes made, 2 to missing)
. bysort date: keep if _n==1
(3 observations deleted)
. drop amount
. rename sum amount
. clist, noobs

       date     amount
10-Oct-1990        189
11-Oct-1990          .
12-Oct-1990        107

Friedrich Huebler

--- "Eric G. Wruck" <[email protected]> wrote:
> I just learned, rather inconveniently, that collapse doesn't work
> the 
> way I'd like when encountering missing values.  Here's an example:
> . l
> 
>       +----------------------+
>       |        date   amount |
>       |----------------------|
>    1. | 10-Oct-1990      200 |
>    2. | 10-Oct-1990      -75 |
>    3. | 10-Oct-1990       64 |
>    4. | 11-Oct-1990        . |
>    5. | 12-Oct-1990      107 |
>       |----------------------|
>    6. | 12-Oct-1990        . |
>       +----------------------+
> 
> . collapse (sum) net_amt=amount, by(date)
> 
> . l
> 
>       +-----------------------+
>       |        date   net_amt |
>       |-----------------------|
>    1. | 10-Oct-1990       189 |
>    2. | 11-Oct-1990         0 |
>    3. | 12-Oct-1990       107 |
>       +-----------------------+
> 
> .
> The problem is for the single 11-Oct-1990 observation.  After 
> collapsing, the missing value becomes a zero; in this instance I 
> would have preferred it remain missing.  The 12-Oct-1990 treatment
> is 
> fine & what I expected.  I suppose I could delete observations
> before 
> performing the collapse but it would be better if there was some 
> other option.  Is there?
> 
> 
> Grazie,
> 
> 
> Eric
> 
> -- 
> 
> ===================================================
> 
>         Eric G. Wruck
>         Econalytics
>         2535 Sherwood Road
>         Columbus, OH  43209
> 
>         ph:      614.231.5034
>         cell:    614.330.8846
>         eFax:    614.573.6639
>         eMail:   [email protected]
>         website: http://www.econalytics.com
> 
> ====================================================


		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com
*
*   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