Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Deviation (Effect) coding in regression in Stata

    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?



    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)
    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?

    Code:
     regress tscore i.gender##i.coed
    gender:  factor variables may not contain negative values
    r(452);
    I did recode gender to be just 0/1 and it returned the same message for coed

    Code:
     regress tscore i.gender##i.coed
    coed:  factor variables may not contain negative values
    r(452);
    Any help on this would be much appreciated. Thank you!

    Katherine Picho

  • #2
    Check out the older/deprecated -xi3- command:

    http://www.stata.com/statalist/archi.../msg00597.html
    http://fmwww.bc.edu/repec/bocode/x/xi3.ado

    However you can accomplish all the same things (and more) using -margins- and -contrast- :

    http://www.stata.com/statalist/archi.../msg00603.html
    __________________________________________________ __
    Assistant Professor, Department of Biostatistics and Epidemiology
    School of Public Health and Health Sciences
    University of Massachusetts- Amherst

    Comment


    • #3
      Here's a basic example:
      Code:
      sysuse auto, clear
      regress price i.rep78
      contrast g.rep78

      Comment

      Working...
      X