You do not need to lose information with dummy coding. Let's take age at menarche as an example of a numerical independent variable that is meaningless for a subpopulation. The intention (if I understand correctly) is to have two models, one for boys and the other for girls, but to fit them both simultaneously using all the data possible. For logistic regression the one for girls will have the form
$$\text{logit}(\Pr(Y=1) \mid \text{girl}) = \color{red}{\beta_0 X} + \color{gray}{(\beta_1 X_1 + \cdots + \beta_p X_p)}$$
where $X$ is age at menarche--expressed however you like--and $X_1, \ldots, X_p$ are all the other variables. (The form of the left hand side might change for other forms of regression, but that's incidental to the topic of variable encoding.) The one for boys is to have the form
$$\text{logit}(\Pr(Y=1) \mid \text{boy}) = \color{blue}{\alpha_0} + \color{gray}{(\beta_1 X_1 + \cdots + \beta_p X_p)}$$
where $X$ no longer enters and $\alpha_0$ is any gender effect. If we define $Z$ to be a dummy for boys (equal to $1$ for them and $0$ otherwise), then both models are subsumed under the general form
$$\text{logit}(\Pr(Y=1)) = \color{blue}{\alpha_0} Z + \color{red}{\beta_0 X}(1-Z) + \color{gray}{(\beta_1 X_1 + \cdots + \beta_p X_p)},$$
as you can readily check by seeing that setting $Z=0$ removes the $\color{blue}{\alpha_0}$ term and reduces the second to $\color{red}{\beta_0 X}$ (the first model) while setting $Z=1$ removes the $\color{red}{\beta_0 X}$ term and keeps the $\color{blue}{\alpha_0}$ term (the second model). The second term, $\color{red}{\beta_0 X}(1-Z)$, is recognizable as an interaction (between gender and age at menarche), making it a familiar construct susceptible to the usual model-building techniques and regression diagnostics.
When performing model-building exercises, you cannot include both $Z$ and $1-Z$ (at least not when the model includes a constant): they are collinear with the constant. This is a case where you must ignore the oft-heard advice to include every variable that is involved in any interaction. The interaction variable $\color{red}{X}(1-Z)$ is easily calculated manually. Just be sure to treat $X$ and $Z$ as a nested pair of variables: it makes no sense to include $X$ without $Z$ (that's the problem of defining age at menarche for boys), although it does make sense to include $Z$ without $X$ (that's a model which includes a gender difference but has dropped the age-at-menarche variable). In effect, to account for age at menarche you must include gender in the model, and then you can decide whether age at menarche helps improve the model for girls alone; it will have no effect on the boys.
A helpful reader (with insufficient reputation to comment) pointed out a potential pitfall in algebraically computing $X(1-Z)$ if $X$ has been recorded as a missing or null value (such as NA
in R
) for the boys, because this could cause $X(1-Z)$ to be missing rather than $0$ as intended (depending on how your computing platform handles missing-value codes). The variable "$X(1-Z)$", which is intended to equal $0$ for boys and $X$ for girls, should be computed with a conditional expression like ifelse(Z==1,0,X)
. This, I hope, further clarifies what I meant by the reference to "nested variables."