Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: collecting interaction terms after estimation

 From Richard Williams To statalist@hsphsun2.harvard.edu, Subject Re: st: collecting interaction terms after estimation Date Sat, 05 Nov 2011 14:10:28 -0500

```At 12:34 PM 11/5/2011, Maria Ana Vitorino wrote:
```
```Dear Richard,
I'm actually using asclogit and it seems that factor variables and
time series operators are not allowed...
Ana
```
```
```
-clogit- allows factor variables, and the help for -clogit- tells how to estimate an -asclogit- model. But, it may just be easier to tweak my original advise. Compute all the original terms and estimate your model. Then recompute those terms fixing distance at 10 and do the predict.
```

```
```On Nov 5, 2011, at 2:20 PM, Richard Williams wrote:

```
```At 11:48 AM 11/5/2011, Maria Ana Vitorino wrote:
```
```Dear statalist users,
Suppose I have the following model in which I regress people's
interacted with distance.
(the Xs refer to interactions between distance to the store and
other people's characteristics).

logit choice dist dist2 ageXdist sexXdist incXdist
```
```
If you have Stata 11 or 12, you are making this too hard. Use factor

clonevar xdist = dist
logit choice i.sex xdist age inc c.xdist#c.xdist c.age#c.xdist
i.sex#c.xdist c.inc#c.xdist

replace xdist = 10 if !missing(xdist)
predict p1, p

Change the last line to

predict p1, p if e(sample)

if you only want to use the same cases that were used in the
estimation.

Then,

drop xdist
clonevar xdist = dist
[repeat process with remaining models; call predictions p2, p3, or
whatever)

Note that you run the logistic regressions using the original values
of distance. You then set distance = 10 and do your predictions. By
using the factor variable notation, Stata will understand how the
value of distance affects both the squared term and the interaction
terms.

Also note that in your original example you did not have the main
effects of sex, age, income or inc. I have added them, but if for
some reason you really really really don't want them you should drop
the main effects from the model.

If you are condemned to using Stata 10 or earlier, you will need to
tweak the approach so that you run the regression, and then
recompute all the terms setting distance to 10 and then doing the
prediction.

```
```And I would like to obtain predicted probabilities for each person
when distance is set to 10.

This would be easy enough if I only had this model specification. But
I have several possible models (and may keep adding and changing the
current ones).

This is what I have so far:

local chars "sex age inc"
foreach varname in `chars'{
gen distX`varname' = dist*`varname'
}
gen dist2= dist*dist

*model 1
logit choice dist dist2 ageXdist sexXdist incXdist

*model 2
logit choice dist dist2  sexXdist incXdist

*model 3
logit choice dist ageXdist  incXdist

My question is then: Is it possible to write code general enough that
would calculate predicted probabilities for when distance is set to
10
for *any* of the above models?

Any insights are appreciated.
Thanks,
Ana
*
*   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/
```
```
-------------------------------------------
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/
```
```
-------------------------------------------
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/
```