Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Chris Yang <[email protected]> |

To |
[email protected] |

Subject |
Re: st: Re: Exclude non-positive values when using collapse |

Date |
Tue, 21 Jan 2014 22:57:07 -0500 |

Hi Joseph, Thanks a lot for your prompt reply. In my example, I collapse by group, so that for group 1 there are only four values for var3: 1, 1, -1, 1. If we exclude the -1, the mean after collapse is (1 + 1 + 1) / 3. If I understand you correctly, after replacing -1 values with missing values, the -collapse- command will simply ignore the missing ones when averaging for variables. Is that correct? Best regards, Chris On Tue, Jan 21, 2014 at 10:44 PM, Joseph Coveney <[email protected]> wrote: > Chris Yang wrote: > > I want to collapse a dataset using the means of the variables. > However, in my data, some variables may contain value -1, and I want > to exclude only such values from the mean calculation for the variable > when collapsing. > > For example, given the following dataset: > > var1 var2 var3 group > 0 1 1 1 > 0 -1 1 1 > 1 0 -1 1 > 1 1 1 1 > 1 1 1 2 > 1 0 0 2 > > After the collapse (by group), for group 1: I want var2 to be (1 + 0 + > 1) / 3 and var3 to be (1 + 1 + 1) / 3, i.e. ignoring -1 values when > averaging. > > How should I do that? Thanks a lot! > > -------------------------------------------------------------------------------- > > Wait a minute. What do you want to do here? Do you want to exclude -1 values > and calculate the mean of the remaining values, or exclude both zero and -1 > values and calculate the mean of the remaining? Your first paragraph says the > first, but your penultimate paragraph says the second (well, sort of--I assume > there's a typo or two for your var3 expression). Either way, what I wrote in > response will work; you just have to revise the missing-value list for > -mvdecode- and the -if- criterion for the manual loop. > > Joseph Coveney > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: Re: Exclude non-positive values when using collapse***From:*"Joseph Coveney" <[email protected]>

**References**:**st: Exclude non-positive values when using collapse***From:*Chris Yang <[email protected]>

**st: Re: Exclude non-positive values when using collapse***From:*"Joseph Coveney" <[email protected]>

- Prev by Date:
**st: Re: Exclude non-positive values when using collapse** - Next by Date:
**Re: st: Re: Exclude non-positive values when using collapse** - Previous by thread:
**st: Re: Exclude non-positive values when using collapse** - Next by thread:
**Re: st: Re: Exclude non-positive values when using collapse** - Index(es):