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: is something wrong with fvvarlist "i(3 4).role"?
From
"Michael N. Mitchell" <[email protected]>
To
[email protected]
Subject
Re: st: is something wrong with fvvarlist "i(3 4).role"?
Date
Mon, 12 Jul 2010 18:56:12 -0700
Dear Lazlo
I think that this is more intuitive when thinking about using the -i.- prefix in the
context of a modeling command, for example...
regress mpg i.rep78
In this situation, we always need a base category for the indicator variables. While a
command like -summarize- supports factor variables, the default behavior is still to
create a reference category. But you can override this. If you want to select all
categories, you can do so like this...
. summ ibn.rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
rep78 |
1 | 69 .0289855 .1689948 0 1
2 | 69 .115942 .3225009 0 1
3 | 69 .4347826 .4993602 0 1
4 | 69 .2608696 .4423259 0 1
5 | 69 .1594203 .3687494 0 1
but if you want to select a subset of categories and have no base category, it looks
like you would need to use the -fvset- command, for example
. fvset base none rep78
. summ i(1 2).rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
rep78 |
1 | 69 .0289855 .1689948 0 1
2 | 69 .115942 .3225009 0 1
I hope this helps this make more sense. It is definitely a different way of thinking about
specifying the levels of variables.
Best regards,
Michael N. Mitchell
Data Management Using Stata - http://www.stata.com/bookstore/dmus.html
A Visual Guide to Stata Graphics - http://www.stata.com/bookstore/vgsg.html
Stata tidbit of the week - http://www.MichaelNormanMitchell.com
On 2010-07-12 5.56 PM, László Sándor wrote:
Thank you, Michael!
I acknowledge this behavior, but I find it strange (= not very
intuitive for most uses of this) and also somewhat contrary to the
manual's explanation (below). So I need to add another arbitrary level
just to be able to introduce the level indicators I originally
intended to? How clumsy...
Thanks again,
Laszlo
Selecting levels
You can select a range of levels -- a range of virtual variables -- by
using the i(numlist). operator.
Examples Description
--------------------------------------------------------------------
i2.cat a single indicator for cat==2
2.cat same as i2.cat
i(2 3 4).cat three indicators, cat==2, cat==3, and cat==4;
same as i2.cat i3.cat i4.cat
i(2/4).cat same as i(2 3 4).cat
2.cat#1.sex a single indicator that is 1 when cat==2 and
sex==1, and is 0 otherwise
i2.cat#i1.sex same as 2.cat#1.sex
--------------------------------------------------------------------
On Tue, Jul 13, 2010 at 2:21 AM, Michael N. Mitchell
<[email protected]> wrote:
Greetings
The trick is that the -i.- is creating a reference group, so in your
example group 3 is the reference group. Here are some examples using the
-auto- dataset.
. sysuse auto
(1978 Automobile Data)
* group 1 is the reference, groups 2-5 are shown
. summ i.rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
rep78 |
2 | 69 .115942 .3225009 0 1
3 | 69 .4347826 .4993602 0 1
4 | 69 .2608696 .4423259 0 1
5 | 69 .1594203 .3687494 0 1
* group 1 is the reference, groups 2-5 are shown
. summ i(1/5).rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
rep78 |
2 | 69 .115942 .3225009 0 1
3 | 69 .4347826 .4993602 0 1
4 | 69 .2608696 .4423259 0 1
5 | 69 .1594203 .3687494 0 1
* group 1 is the reference, groups 2-4 are shown
. summ i(1/4).rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
rep78 |
2 | 69 .115942 .3225009 0 1
3 | 69 .4347826 .4993602 0 1
4 | 69 .2608696 .4423259 0 1
* group 1 is the reference, groups 2-3 are shown
. summ i(1/3).rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
rep78 |
2 | 69 .115942 .3225009 0 1
3 | 69 .4347826 .4993602 0 1
* group 1 is the reference, group 2 is shown
. summ i(1/2).rep78
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
2.rep78 | 69 .115942 .3225009 0 1
I hope that helps.
Michael N. Mitchell
Data Management Using Stata - http://www.stata.com/bookstore/dmus.html
A Visual Guide to Stata Graphics - http://www.stata.com/bookstore/vgsg.html
Stata tidbit of the week - http://www.MichaelNormanMitchell.com
On 2010-07-12 4.21 PM, László Sándor wrote:
Hi all,
I think I have a straightforward question in the subject line.
I use the up-to-date Stata on a mac. The factor variable handling does
not work as promised in the manual (cf. -h fvvarlist-). See the most
striking, simple example below. Or am I missing the obvious?
Thank you,
Laszlo
. sum i(3 4).role
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
4.role | 747 .2503347 .433496 0 1
. sum i(3/4).role
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
4.role | 747 .2503347 .433496 0 1
*
* 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/