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]
Re: st: Re: Exclude non-positive values when using collapse
From
"Joseph Coveney" <[email protected]>
To
<[email protected]>
Subject
Re: st: Re: Exclude non-positive values when using collapse
Date
Wed, 22 Jan 2014 13:57:15 +0900
Chris Yang wrote:
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?
--------------------------------------------------------------------------------
Sorry, I skipped over the by-group part by accident. As to your question, here's
one way to find out.
Joseph Coveney
. input byte(var1 var2 var3 group)
var1 var2 var3 group
1. 0 1 1 1
2. 0 -1 1 1
3. 1 0 -1 1
4. 1 1 1 1
5. 1 1 1 2
6. 1 0 0 2
7. end
. mvdecode var?, mv(-1)
var2: 1 missing value generated
var3: 1 missing value generated
. collapse (mean) var?, by(group)
. list, noobs
+-------------------------------+
| group var1 var2 var3 |
|-------------------------------|
| 1 .5 .666667 1 |
| 2 1 .5 .5 |
+-------------------------------+
. exit
end of do-file
*
* 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/