Dear all,

I'm currently trying to analyze the interaction effects of regional health indicators (e.g. regional hospital density) and earnings quartile on mortality.
In detail, I want to analyze whether the effect of hospital density on mortality is different for individuals of different earnings quartiles.

Specifically, I run the following regression:

Code:
logit death c.age##earnings_rank c.age2##earnings_rank c.age3##earnings_rank c.age4##earnings_rank
year##earnings_rank hosp_density_quartile##earnings_rank
where "death" is a dummy variable which has the value 1 if the individual dies in year X; and zero otherwise.
To treat hospital density as categorical variable, I use the variable "hosp_density_quartile" which states where the home region of the respective individual ranks in terms of hospital density.
I use different specifications of age (age, age^2, age^3, age^4).

After running this logic regression, I want to use the -margins- and -marginsplot- command to analyze which role a regions hospital density plays for individuals mortality risk.
I want to compare these effects for individuals with different positions in the earnings distribution. So I want to generate for each earnings quartile one marginsplot where on the y-axis there is Probability of death; x-axis there is age and there are 4 different lines for the 4 different hospital density quartiles.

I tried to run the following code where I used interactions of age instead of age2, age3 and age4 (because it was said in other posts that margins has problems dealing with it otherwise)

Code:
logit death c.age##earnings_rank c.age#c.age##earnings_rank c.age#c.age#c.age##earnings_rank c.age#c.age#c.age#c.age##earnings_rank year##earnings_rank hosp_density_quartile##earnings_rank

forval r = 1/4 {
  margins hosp_density_quartile, at(age==(20(5)55) earnings_rank = (`r'))
  marginsplot, name (f`r', replace) title(`r'th quartile)
  }
However, unfortunately no margins where calculated. In the columns of the output it said ". (not estimable)."
I would be very grateful if someone would have an idea where the mistake in my code is?

Thank you very much in advance.

_____________________

FYI: An example of my data looks like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(age death earnings_rank hosp_density_quartile) int(year age2) long(age3 age4)
78 0 1 4 2000 6084 474552 37015056
60 0 4 3 1994 3600 216000 12960000
89 1 2 1 2005 7921 704969 62742241
72 1 3 2 1999 5184 373248 26873856
91 0 1 3 2010 8281 753571 68574961
end