Warm tip: This article is reproduced from stackoverflow.com, please click
stata

Make continuous variable the baseline when interacting with factor variable (stata)

发布于 2020-05-06 12:56:59

Consider two variables sex and age, where sex is treated as categorical variable and age is treated as continuous variable. I want to specify the full factorial using the non-interacted age-term as baseline (the default for sex##c.age is to omit one of the sex-categories).

The best I could come up with, so far, is to write out the factorial manually (and omitting `age' from the regression):

reg y sex#c.age i.sex

This is mathematically equivalent to

reg y sex##c.age

but allows me to directly infer the regression coefficients (and standard errors!) on the interaction term sex*age for both genders.

Is there a way to stick to the more economic "##" notation but make the continuous variable the omitted category?

(I know the manual approach has little overhead notation in the example given here, but the overhead becomes huge when working with triple-interaction terms).

Questioner
Bob
Viewed
26
Bob 2020-02-21 07:00

Not a complete answer, but a workaround: One can use `lincom' to obtain linear combinations of coefficients and standard errors. E.g., one could obtain the combined effects for both sexes as follows:

reg y sex##c.age
forval i = 1/2 {
    lincom age + `i'.sex#c.age
    }