[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Scott Merryman <scott.merryman@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Collapse with sum function and missing values |

Date |
Wed, 10 Feb 2010 16:29:06 -0600 |

Here one way, though calling -collapse- twice might not be the most efficient method: clear input group x group x 1 10 1 11 1 12 2 20 2 21 2 22 3 . 4 . 4 . 5 0 5 0 end tempfile tmp1 tmp2 save `tmp1' collapse (sum) x, by(gro) sort gr save `tmp2' use `tmp1' collapse (sum) x, by(gro) cw sort gr merge 1:m gr using `tmp2', replace x = . if _m ==2 drop _m l Scott On Wed, Feb 10, 2010 at 4:13 PM, Michael Mitchell <Michael.Norman.Mitchell@gmail.com> wrote: > Thanks all, both for the general thoughts on the underlying rationale > for this, as well as the practical suggestions. As some noted, I could > do this... > > . collapse (sum) x (count) nonmiss=x, by(group) > . replace x=. if nonmiss==0 > > I have about 100 "x" values, and there is no pattern to the names. All > methods I can think of for ensuring that the "x" values are . when all > members of the group are . involve either substantial typing or a fair > amount of programming. Am I overlooking a simple solution for this? > > Thanks, > > Michael > > > > On Wed, Feb 10, 2010 at 7:14 AM, Martin Weiss <martin.weiss1@gmx.de> wrote: >> >> <> >> >> >> >> As in http://www.stata.com/statalist/archive/2010-02/msg00428.html ? >> >> >> >> HTH >> Martin >> >> >> -----Ursprüngliche Nachricht----- >> Von: owner-statalist@hsphsun2.harvard.edu >> [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Elizabeth >> Allred >> Gesendet: Mittwoch, 10. Februar 2010 16:12 >> An: statalist@hsphsun2.harvard.edu >> Betreff: Re: st: Collapse with sum function and missing values >> >> Michael might use collapse (count) and then set his sum to missing when >> count=0. >> >>>>> On 2/10/2010 at 10:06 AM, in message >> <1F1A9AC9-4E03-488D-ADA4-971B6A192CEE@bc.edu>, Kit Baum <baum@bc.edu> wrote: >> <> > >>> This is somewhat semantic. The presence of 3 and 4 in the group id >> suggests >>> that such groups exist; they merely have no members in the present sample. >> It >>> should be easy enough to -mvdecode- x==0 to x==. >>> >>> This reminds me of a grouse I had about the calculation of the s.d. of >> data >>> that were all missing. The mean of these data was computed properly as >>> missing, but the s.d. was reported as 0. Pedantically, as all values took >> on >>> the same NAN value, there was indeed zero variance. I convinced StataCorp >>> that this was not a good idea, and that the s.d. or variance of data that >> are >>> all missing is indeed missing. That is now what -tabstat- does. >>> >>> Kit >>> >>> On Feb 10, 2010, at 2:33 AM, Michael wrote: >>> >>>> Shouldn't the value of -x- for groups 3 and 4 be missing, not zero. >>>> To me, the sum of a series of missing values is a missing value. I am >>>> doing a collapse for about 100 variables (100 x values) and need the >>>> value to be defined as missing (not 0) in such cases. Any ideas? >>> >>> >>> Kit Baum | Boston College Economics & DIW Berlin | >>> http://ideas.repec.org/e/pba1.html >>> An Introduction to Stata Programming | >>> http://www.stata-press.com/books/isp.html >>> An Introduction to Modern Econometrics Using Stata | >>> http://www.stata-press.com/books/imeus.html >>> >>> >>> * >>> * For searches and help try: >>> * http://www.stata.com/help.cgi?search >>> * http://www.stata.com/support/statalist/faq >>> * http://www.ats.ucla.edu/stat/stata/ >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ >> >> >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ >> > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: Collapse with sum function and missing values***From:*Kit Baum <baum@bc.edu>

**Re: st: Collapse with sum function and missing values***From:*"Elizabeth Allred" <lizard@hsph.harvard.edu>

**Re: st: Collapse with sum function and missing values***From:*Michael Mitchell <Michael.Norman.Mitchell@gmail.com>

- Prev by Date:
**RE: st: about the temporal desagragation** - Next by Date:
**Re: st: Collapse with sum function and missing values** - Previous by thread:
**Re: st: Collapse with sum function and missing values** - Next by thread:
**RE: st: Collapse with sum function and missing values** - Index(es):

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