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

From |
"Jian Zhang" <jzh@ucdavis.edu> |

To |
"Eric G. Wruck" <ewruck@econalytics.com>, statalist@hsphsun2.harvard.edu |

Subject |
RE: st: Collapse & Missing Values |

Date |
Wed, 28 Sep 2005 12:22:26 -0700 (PDT) |

I run into the same problem. What I know is the following: id var1 var2 1 12 . 1 14 2 2 16 . 2 17 . if you type gen var3=var1+var2, stata will give you: id var1 var2 var3 1 12 . . 1 14 2 16 2 16 . . 2 17 . . However, if you type sort id by id: egen var3=sum(var2), stata will give you id var1 var2 var3 1 12 . 2 1 14 2 2 2 16 . 0 2 17 . 0 I wonder who can explain the way state deals with missing values? Is there any general rule for stata? Thanks. Jian > 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: ewruck@econalytics.com > website: http://www.econalytics.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/ > * * 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/

- Prev by Date:
**Re: st: interaction** - Next by Date:
**st: Re: Matrix Kronecker Product Question** - Previous by thread:
**st: Re: Collapse & Missing Values** - Next by thread:
**RE: st: Collapse & Missing Values** - Index(es):

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