Sue Kim wrote:
Is there a way to custom contrast a categorical
variable in Stata? After running a logit model with a
categorical variable with 5 categories, how would you
compare category 1,2,3 vs 4,5 or other combinations
when the output always drops the reference group?
--------------------------------------------------------------------------------
Run the following do-file and see whether it helps.
Joseph Coveney
clear
set more off
set seed `=date("2005-06-22", "ymd")'
set obs 200
egen byte predictor = fill(1 2 3 4 5 1 2 3 4 5)
generate byte response = uniform() < 0.5
xi: logit response i.predictor, nolog
* Category 1 = _cons
* Category 2 = _cons + _Ipredictor_2
* Category 3 = _cons + _Ipredictor_3
* etc.
* Compare Categories 1, 2 and 3 to Categories 4 and 5:
lincom (_cons + _cons + _Ipredictor_2 + _cons + _Ipredictor_3) / 3 - ///
(_cons + _Ipredictor_4 + _cons + _Ipredictor_5) / 2
* Notice that -lincom- factors _cons out of the contrast equation,
* and divides both sides of the contrast equation by it.
* (_cons thus disappears)
*
* An alternative illustration:
tabulate predictor, generate(predictor_)
logit response predictor_*, noconstant nolog
lincom (predictor_1 + predictor_2 + predictor_3) / 3 - ///
(predictor_4 + predictor_5) / 2
* Both of the previous -lincom-s show the linear predictor;
* To send the linear predictor back through the link function:
lincom (predictor_1 + predictor_2 + predictor_3) / 3 - ///
(predictor_4 + predictor_5) / 2, or
exit
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/