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]
st: Exclude non-positive values when using collapse
From
Chris Yang <[email protected]>
To
[email protected]
Subject
st: Exclude non-positive values when using collapse
Date
Tue, 21 Jan 2014 22:25:38 -0500
Dear All,
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!
Best regards,
Chris
*
* 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/