Bookmark and Share

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: Categorical variable and -nestreg-


From   Richard Williams <[email protected]>
To   [email protected], [email protected]
Subject   Re: st: Categorical variable and -nestreg-
Date   Wed, 04 Sep 2013 08:24:57 -0500

Glad you got something to work. I suggested to Statacorp a while back that nestreg should support factor variables, but for whatever reason it hasn't happened. For this and other reasons, -xi- continues to be useful.

FYI, you reversed our contributions, but then that is going to happen when you have Richard Williams and William Buchanan in the same thread. I've spent much of my life being called "Bill".

At 10:04 PM 9/3/2013, David de Jong wrote:
Hi Richard and Billy,

Thanks for your responses.

Richard, you?re correct that when I create the interaction terms
first, the syntax runs fine. So, this means that -nestreg- can use
categorical variables, but the problem was that I didn?t realize that
using factor variable notation means that all variables within that
new interaction term will be treated as factor variables.

Thanks for pointing that out, Billy. I?m using Stata 12.1, and I
haven?t been able to find reference to this restriction in the
documentation.

Regarding my claim that using xi: returns the same error.  Billy's
surprise that it didn't work prompted me to dig deeper. Turns out I
was mistaken: it does work, but I had to first figure out that in an
interaction term between a categorical and continuous variable, the
categorical variable must come first, and I needed to use ?*? and not
?#?.

So, to recap, two solutions to entering interactions with categorical
variables into ­nestreg- are to either compute them before hand or to
use xi:.

Thanks for all of the help!

David de Jong


On Mon, Sep 2, 2013 at 10:03 PM, Richard Williams
<[email protected]> wrote:
>
> At 07:21 PM 9/2/2013, William Buchanan wrote:
>>
>> Check your syntax again. The issue is probably with the interaction terms that you include using factor variable notation. Create the interactions first as new variables and try using those instead.
>
>
> Beat me to it. But elaborating a bit:
>
> Yes, nestreg does not allow factor variables. I'm not sure where that is noted in the documentation but it is clear that that is the case.
>
> Further, because of the c. notation, there would be a problem even if condition was continuous too. I think of factor variables as being categorical. But if I am reading the docs right, if you say c.var1, var1 is also now considered a factor variable. The Stata 13 Users Guide section 11.4.3.1 says "i.group is called a factor variable, although more correctly, we should say that group is a categorical variable to which factor-variable operators have been applied. There are five factor-variable operators:...c. unary operator to treat as continuous."
>
> So if I am reading that right, we could say "c.var1 is called a factor variable, although more correctly, we should say that var1 is a continuous variable to which factor-variable operators have been applied."
>
> Whether I am phrasing it right or not, if you use notation like c.var1, you can get the error message "factor variables not allowed."
>
> One other tidbit: If there are no interaction terms, Stata assumes vars are continuous unless you use i. to tell it otherwise. But if you have interaction terms, e.g. v1#v2, Stata assumes that both terms are categorical unless you add the c. notation. Which seems a bit inconsistent to me but I suppose there is some reason for it.
>
> I am a little surprised, though, that xi: does not work. Can you show the exact syntax? The help for xi says
>
> i.varname1*varname3 creates dummies for categorical variable varname1 and continuous variable varname3: all interactions and main effects
>
> So, I think if you got rid of the c. parts, xi and nestreg together would work.
>
>
>
>> HTH,
>> Billy
>>
>> Sent from my iPhone
>>
>> On Sep 2, 2013, at 19:09, David de Jong <[email protected]> wrote:
>>
>> > Hello all,
>> >
>> > New Stata user here. I'm trying to use -nestreg- to run a hierarchical
>> > (not stepwise) regression. I'm having some trouble, and I was hoping
>> > someone could lend a hand. This is the syntax:
>> >
>> > nestreg: regress z_target_RT_c12 (condition) ///
>> > (z_neutral_RT_c12 z_nonword_RT_c12 z_int_goals_c12 z_enhance_goals_c12) ///
>> > (c.z_int_goals_c12#condition c.z_enhance_goals_c12#condition)
>> >
>> > Condition is categorical, with 2 possible values. All other variables
>> > are continuous.
>> >
>> > When I run the syntax, I receive the error:
>> > factor variables not allowed
>> > r(101);
>> >
>> > I've figured out nestreg can't handle factor variables, as indicated
>> > by this error message. I've tried using "xi:" before "nestreg" and
>> > appending "i." to "condition" but I still get the "factor variables
>> > not allowed" error message. Is it simply the case that I cannot use
>> > -nestreg- for categorical variables? If so, are there other ways to
>> > deal with this?
>> >
>> > Thanks so much,
>> >
>> > David de Jong
>> > *
>> > *   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/
>
>
> -------------------------------------------
> Richard Williams, Notre Dame Dept of Sociology
> OFFICE: (574)631-6668, (574)631-6463
> HOME:   (574)289-5227
> EMAIL:  [email protected]
> WWW:    http://www.nd.edu/~rwilliam
>
>
> *
> *   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/




--
~
Department of Clinical and Social Sciences in Psychology
University of Rochester
498c Meliora Hall
Rochester, NY 14627

*
*   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/

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
HOME:   (574)289-5227
EMAIL:  [email protected]
WWW:    http://www.nd.edu/~rwilliam


*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index