# How can one incorporate a variable that can take a categorical or numeric value into a regression?

The variable I am interested in is "time living in the area". This only applies to people who were born elsewhere and then migrated to the area in question.

My intuition tells me I would model "migrant" as one variable and "time living in the area" as another, then only place the interaction term into the regression. That way, "natives" would be the reference level and the resulting coefficient would describe the change in my dependent variable with years of residence in case the individual is a migrant.

Is this approach correct, are there any others I should be aware of?

• I don't understand your question. It seems to be a very broad question and does not appear to me to be well-defined. Mar 28, 2017 at 15:56
• You need to include the "migrant" indicator in the regression along with the interaction. Otherwise, what you are doing is tantamount to asserting that natives all have zero time living in the area. See, inter alia, the analysis of a comparable situation at stats.stackexchange.com/a/4833/919. And perhaps stats.stackexchange.com/questions/6563 is the same question as yours?
– whuber
Mar 28, 2017 at 16:00
• @whuber The way the question was asked, the variable only contains number of years living in the area for migrants and is otherwise a special "Always lived here" value. Naturally I could infer that time from the respondent's age, though now that I think about it, perhaps it would be best to represent "time living in an area" as a fraction of the respondent's age rather than an absolute value. The links have been helpful, thank you. Mar 28, 2017 at 16:14

If you have a dependent variable $Y_i$, and you are interested in the effect of time living in area ($tia$) and migrant status ($migrant$), you could fit the model: $$Y_i=\beta_0+\beta_1migrant_i+\beta_2tia_i+\beta_3migrant:tia_i+\epsilon_i$$

Note that you would not normally remove the individual variables and just retain the interaction. The marginal effect for migrants would be derivative of $migrant$ with respect to $Y_i$:

$$\frac{d(migrant)}{d(Y_i)}=\beta_1+\beta_3tia_i$$

I am guessing this may be what you are getting at with your question, but if you clarify your question we may be able to help you further :)

• I think it might not have been clear, but $migrant$ and $tia$ are derived from the same measurement, so I would need to assign some arbitrary value to $tia$ for when $migrant = 0$. Thinking more about the question I'm trying to tackle, it seems as if might make more sense to consider $tia$ as a fraction of the respondent's age rather than taking its absolute value. Thank you for the reply. Mar 28, 2017 at 16:42
• If you have an indicator for migrant status, you can use that as $migrant$ in the above and fit the model. If you have the respondents age, you can use that to identify migrant status and define the dummy variable $migrant$. Then you can fit the above model. I am not sure how assigning arbitrary values to $tia$ is going to be helpful.
– Wes
Mar 29, 2017 at 8:08
• The reason I think transforming $tia$ might be helpful is because I would expect that living, say 5 years in a given area won't be the same if you're 20 (that's 25% of your life) than if you're 50 (only 10%). I am not sure either way though, so perhaps it will be best to try out different models. Mar 29, 2017 at 13:53