Dear Statalist users,

I wondered if you could help me with this issue in particular.

I am running a regression with Education, measured in years, as my output variable, and amongst other regressors are the two of interest for this problem, age and nuclear (where nuclear is a 0,1 dummy of family type).

At the bottom is an example of the data to assist with this. I have included 250 random observations from >100,000.








Now, I specifically want to include age as a categoric, not continuous variable. The reason being, in my sample, I find a non-linear contribution of age to education, and hence want to plot the impact of each age (1,2,3,4) etc on education. As such, in my first regression, I do the following:

Code:
reg educ nuclear i.age female
coefplot, keep (*.age) vertical xlabel(#25) xtitle("Age") ytitle("Years of Education")
This produces a graph of the data of impact on education of each Age group, which I am happy with.

The issue is when I interact age with my coefficient, nuclear.

Code:
reg educ i.age#i.nuclear female

regress, coefleg

coefplot, keep (*.age#*) vertical xlabel(#25) xtitle("Age") ytitle("Years of Education")
I specifically do this, as I am interested in plotting two separate curves; one for the effect on education of age when nuclear=0 and when nuclear=1. I believe reporting it like this would be most useful in interpreting the results.

When I do this, I am unable to plot the graph I am interested in as it plots only the result for when nuclear==1. I am unable to work out how to get it to plot the coefficients for effect on education of age for nuclear==0. In particular, my ideal graph would be one with both nuclear==1 and nuclear==0 plotted on two separate lines within the same graph, to distuingish these effects over ages.

Would someone kindly be able to help with this? I have read many posts on coefplot and some discussing using categoric variables, hence I was able to work out to use keep(*.age#*), but when I try keep(*.age#0b.nuclear), it says no observations were plotted, even though the name should be correct according to coefleg.

Thanks in advance!


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int educ float nuclear int(age female)
 0 0  0 0
 0 0  0 0
 0 1  0 1
 0 0  0 1
 0 1  0 1
 0 1  0 0
 0 0  0 0
 0 1  0 1
 0 1  0 1
 0 0  1 1
 0 0  1 1
 0 0  1 0
 0 1  1 1
 0 1  1 0
 0 1  1 1
 0 0  1 0
 0 1  2 0
 0 0  2 1
 0 0  2 1
 0 0  2 1
 0 0  2 1
 0 0  2 0
 0 1  2 0
 1 1  3 0
 0 1  3 1
 0 0  3 0
 0 0  3 1
 0 1  3 0
 0 0  3 0
 0 0  3 0
 0 0  3 1
 0 0  4 1
 0 0  4 0
 0 1  4 0
 0 1  4 0
 0 1  4 0
 0 0  4 0
 0 1  4 0
 0 0  5 0
 0 1  5 0
 1 1  5 1
 0 1  5 1
 0 1  5 0
 1 0  5 0
 0 1  5 1
 0 1  5 1
 0 0  5 0
 0 0  5 1
 0 0  5 1
 0 0  5 1
 1 0  5 1
 1 0  5 0
 0 0  5 0
 0 1  5 1
 0 1  5 0
 0 0  5 1
 0 0  5 1
 0 0  6 0
 0 0  6 1
 0 0  6 0
 0 0  6 1
 1 0  6 0
 0 1  6 1
 0 0  6 0
 1 0  6 1
 0 0  6 0
 0 1  6 0
 0 1  6 1
 1 1  7 0
 1 0  7 1
 2 1  7 1
 1 1  7 0
 2 1  7 0
 1 0  7 0
 1 0  7 1
 1 0  7 0
 2 1  7 1
 1 1  7 1
 2 1  7 1
 2 1  7 0
 1 0  7 1
 2 0  7 1
 0 1  7 1
 2 0  7 1
 1 1  7 1
 2 0  7 1
 0 0  7 0
 2 1  7 0
 2 0  7 1
 0 0  7 1
 0 0  7 1
 1 0  7 0
 2 1  7 0
 3 1  8 1
 2 1  8 0
 2 0  8 1
 3 1  8 0
 2 1  8 1
 3 1  8 1
 3 1  8 1
 3 1  8 1
 2 1  8 1
 1 0  8 1
 0 1  8 1
 0 1  8 1
 3 0  8 0
 3 1  8 0
 3 0  8 1
 1 1  9 0
 2 1  9 0
 4 0  9 0
 5 1  9 1
 3 1  9 1
 3 1  9 0
 4 0  9 0
 2 1  9 0
 4 0  9 1
 4 1  9 0
 2 1  9 0
 4 0  9 0
 2 1  9 1
 2 1  9 0
 0 0  9 0
 0 0  9 1
 4 1  9 1
 3 0  9 1
 5 0 10 0
 5 0 10 1
 5 1 10 1
 4 0 10 1
 2 1 10 0
 5 0 10 0
 4 1 10 1
 5 1 10 1
 4 1 10 0
 2 1 10 1
 5 0 10 1
 3 0 10 0
 3 0 10 0
 2 0 10 0
 1 1 10 0
 4 0 10 1
 3 0 10 1
 2 1 10 1
 5 0 10 0
 4 1 10 1
 4 0 10 1
 5 1 10 1
 3 0 10 0
 3 0 10 1
 2 0 10 0
 4 0 10 1
 4 0 10 0
 5 1 11 1
 4 1 11 0
 4 0 11 0
 6 0 11 1
 7 1 11 1
 6 0 11 0
 5 1 11 0
 6 0 11 0
 5 1 11 1
 2 0 11 1
 6 0 11 1
 3 0 11 0
 3 1 11 0
 5 1 11 1
 6 1 12 0
 7 1 12 0
 6 0 12 0
 6 1 12 0
 5 1 12 0
 5 0 12 0
 4 1 12 0
 6 1 12 1
 7 1 12 1
 6 0 12 1
 6 0 12 0
 6 1 12 0
 6 0 12 0
 6 1 12 0
 6 0 12 0
 7 1 12 0
 7 1 12 0
 6 1 12 0
 6 1 12 1
 6 1 12 1
 4 0 12 0
 7 1 13 0
 9 1 13 1
 9 1 13 0
 6 0 13 1
 8 1 13 1
 5 1 13 0
 7 1 13 1
 3 1 13 0
 6 0 13 1
 5 0 13 0
 7 0 13 0
 8 1 13 1
 5 1 13 0
 7 1 13 0
 8 1 13 0
 6 0 13 0
 5 1 13 0
 8 1 13 0
 8 1 13 1
10 0 14 1
 7 1 14 0
 0 1 14 1
 3 1 14 1
 0 1 14 1
 0 1 14 0
 8 1 14 0
 9 1 14 1
 8 1 14 0
 0 0 14 1
 7 0 14 0
 9 0 14 1
 9 1 14 0
 9 0 14 0
 7 1 15 0
 4 0 15 0
 8 1 15 1
 8 1 15 1
 8 0 15 0
 9 1 15 1
 8 1 15 0
 3 1 15 1
 7 1 15 0
 9 1 15 1
 8 1 15 0
 9 0 15 0
 8 0 15 1
 9 1 15 0
10 0 15 0
 8 0 15 0
11 1 15 1
 9 1 15 0
 9 1 15 1
 9 1 15 0
 9 0 15 1
11 0 15 1
 9 1 15 0
 7 1 15 1
 8 1 16 0
 0 0 16 0
10 0 16 0
10 1 16 0
10 1 16 0
end
label values educ ED6
label def ED6 0 "none, <1 0", modify
label def ED6 1 "1st class 1", modify
label def ED6 2 "2nd class 2", modify
label def ED6 3 "3rd class 3", modify
label def ED6 4 "4th class 4", modify
label def ED6 5 "5th class 5", modify
label def ED6 6 "6th class 6", modify
label def ED6 7 "7th class 7", modify
label def ED6 8 "8th class 8", modify
label def ED6 9 "9th class 9", modify
label def ED6 10 "Secondary 10", modify
label def ED6 11 "11th Class 11", modify
label values female female1
label def female1 0 "Male", modify
label def female1 1 "Female", modify