Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

RE: st: Understanding Factor variables - is order significant ?


From   "Kieran McCaul" <Kieran.McCaul@uwa.edu.au>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Understanding Factor variables - is order significant ?
Date   Wed, 26 May 2010 13:41:44 +0800

....

It's a bug, I believe.

In the example below there are two dichotomous variables, x1 and x2.
I declare the reference level for x1 to be x1=1 and leave x2 at its
default, x2=0.

If I fit x2#ib1.x1, all is well and x1=1/x2=0 is recognised as the
reference level.

If, on the other hand, I fit ib1.x1#x2, x1=1/x2=0 is recognised as the
reference level and dropped, but x1=0/x2=0 is also dropped.



 
clear
set obs 50000
set seed 101954

generate x1 = runiform() > 0.6 
generate x2 = runiform() > 0.7

generate xb = 2 + 0.75*x1 + 1.25*x2 + 1.5*x1*x2

generate exb = exp(xb) 
generate py = rpoisson(exb) 

* This is correct
poisson py x2##ib1.x1

* this is also correct
poisson py x2#ib1.x1
fvexpand x2#ib1.x1
return list
* This is correct - explicity dropping x2=0/x1=1, the reference level.
poisson py 0b.x2#0.x1 1.x2#0.x1 1.x2#1b.x1

* This is incorrect
poisson py ib1.x1#x2
fvexpand ib1.x1#x2
return list
* this is incorrect - explicity dropping x2=0/x1=1, the reference level.
poisson py 0.x1#0b.x2 0.x1#1.x2 1b.x1#1.x2
* this is why. Both x1=0/x2=0 and x1=1/x2=0 are being dropped
poisson py 0.x1#1.x2 1b.x1#1.x2



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael N.
Mitchell
Sent: Wednesday, 26 May 2010 12:41 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Understanding Factor variables - is order significant ?

Dear Richard

   That is an excellent summary, and I agree completely. Thanks for
patiently walking me 
through this! I hope others have enjoyed this :) .

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-05-25 9.22 PM, Richard Williams wrote:
>> This is a perplexing state of affairs! I don't know how to explain
this!
>>
>> I hope someone can help explain!
>
> Michael, I am relieved that someone else is confused! Tweaking your
code
> a bit,
>
> use http://www.ats.ucla.edu/stat/stata/dae/poissonreg, clear
> gen himath = math > 50
> poisson daysabs himath#male, nolog
> poisson daysabs ib0.male#ib1.himath, nolog
> poisson daysabs ib1.himath#ib0.male, nolog
> poisson daysabs ib0.male##ib1.himath, nolog
> poisson daysabs ib1.himath##ib0.male, nolog
>
> The first 2 models give the correct result -- LR Chi-square = 202.49.
> The 3rd gives the incorrect result of LR chi-square = 144.99. The last
2
> commands, using ## instead of #, also give the correct results.
>
> In the few examples we've tried where we knew the correct answer, it
> looks like interactions of the form b0.x1#b1.x2 worked fine but
> b1.x2#b0.x1 caused problems. Further, plain old regress seems to work
> fine regardless of how you do the interactions but ml techniques like
> poisson and ologit have problems.
>
> I strongly suspect there is some sort of bug here. But if not, maybe
> we'll get a fascinating explanation that will greatly add to our
> understanding of interaction effects!
>
> -------------------------------------------
> Richard Williams, Notre Dame Dept of Sociology
> OFFICE: (574)631-6668, (574)631-6463
> HOME: (574)289-5227
> EMAIL: Richard.A.Williams.5@ND.Edu
> WWW: http://www.nd.edu/~rwilliam
>
> *
> * 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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index