You can also use -adjust- after -xtlogit-; it's simpler and more direct, as
illustrated by the (corrected) do-file below.
Joseph Coveney
-------------------------------------------------------------------------------
I wrote:
You can get what you want by generating extra observations containing
covariates with values where you want them for the predictions, and then set
the random effect to zero. It's illustrated in the following do-file.
----------------------------------------------------------------------------
* creating fictional dataset here
clear
set more off
set seed 20040511
set obs 200
generate int pid = _n
forvalues i = 1/3 {
generate byte y`i' = uniform() > 0.5
generate float xcon`i' = uniform()
generate byte xcat`i' = int(5 * uniform()) + 1 // rectified
}
generate byte sex = uniform() > 0.5
reshape long xcat xcon y, i(pid) j(tim)
* model fitted here
xi: xtlogit y xcon sex i.xcat, i(pid)
* obtaining predicted probabilities using -adjust- here
adjust xcon _Ixcat_2=0 _Ixcat_3=1 _Ixcat_4=0 _Ixcat_5=0, by( sex) pr
adjust xcon=5 _Ixcat_2=0 _Ixcat_3=1 _Ixcat_4=0 _Ixcat_5=0, by( sex) pr
* creating predictions beginning here
set obs 604
summarize xcon // rectified (for time-varying covariate)
replace xcon = r(mean) in 601/602
replace sex = 0 in 601
replace sex = 1 in 602
forvalues i = 2/5 { // rectified for five categories
replace _Ixcat_`i' = 0 in 601/l
}
replace _Ixcat_3 = 1 in 601/l
replace xcon = 5 in 603/l
replace sex = 0 in 603
replace sex = 1 in 604
predict y_hat, pu0
slist in 601/l // <- this has the predictions you want
exit
----------------------------------------------------------------------------
Christer Thrane wrote
While there are numerous semi-automatic ways of getting predicted
probabilities for regular logit/probit models, I cannot find these for
xtlogit/xtprobit.
My model (in Stata) is:
xtlogit y gender xcon xcat, re
where
y is a binary variable measured at three time points
gender is coded 1 for male and zero for female
xcon is a continionus time-varying covariate
xcat is an ordinal time-varying covariate with five values.
I want to get the following predicted probabilities:
(1) for men and women, respectively, with xcon = mean and xcat = 3
(2) for men and women, respectively, with xcon = 5 and xcat = 3
*
* 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/