Hello:
I'm using stata 12. I have 2 questions:
1. How do I code variables in Stata using effect/deviation coding? My searches on this issue turned up using xi3: which is not fully supported in recent Stata versions.
I have 2 variables that I'd like to 'effect' code
gender: males = -1 and females = 1
coed: The variable coed is derived from 2 variables: sex and type of school such that, 0 = males, coed -1 = females coed and 1 = females same sex
Admittedly I've never used effect coding before (dummy coding is what I'm used to). So I did the following in Stata to code my variables (probably a bad idea...I will let you be the judge). My question is: did I do this correctly?? If not, what is the correct way to do it?
2. I attempted to run a regression with these variables predicting a dependent variable (tscore) [ this is really just to check for redundancy & eliminate one of the group variables in a model I'm attempting to build-- so don't worry too much about the content for now). However, when I do this, stata gives me an error message that factor variables cant contain negative values. If this is the case, then how does stata handle effects coded variables in regression analyses?
I did recode gender to be just 0/1 and it returned the same message for coed
Any help on this would be much appreciated. Thank you!
Katherine Picho
I'm using stata 12. I have 2 questions:
1. How do I code variables in Stata using effect/deviation coding? My searches on this issue turned up using xi3: which is not fully supported in recent Stata versions.
I have 2 variables that I'd like to 'effect' code
gender: males = -1 and females = 1
coed: The variable coed is derived from 2 variables: sex and type of school such that, 0 = males, coed -1 = females coed and 1 = females same sex
Admittedly I've never used effect coding before (dummy coding is what I'm used to). So I did the following in Stata to code my variables (probably a bad idea...I will let you be the judge). My question is: did I do this correctly?? If not, what is the correct way to do it?
Code:
gen gender = -2 if (sex==0) /* where for variable sex : 0= males, 1 = females*/ replace gender = 1 if (sex==1) gen bcoed = 0 if (sex==0) & (schtype ==0) gen gcoed = -1 if (sex==1) & (schtype==0) gen gss = 1 if (sex==1) & (schtype==1) egen coed = rowmax (bcoed gcoed gss)
Code:
regress tscore i.gender##i.coed gender: factor variables may not contain negative values r(452);
Code:
regress tscore i.gender##i.coed coed: factor variables may not contain negative values r(452);
Katherine Picho
Comment