I have a panel dataset with county-year observations and look into spatial differences of the treatment effect. To this aim, I estimate the following model with OLS:
reg depvar c.treat##i.border i.year i.id, cluster(id)
My estimation results show that the treatment only has significant effects on the dependent variable in counties in the border region. So far, so good. Now, I would like to present these results graphically and plot both the effect in inland and border counties. The treatment effect for border counties totals the coefficient of treat and the interaction term. For convenience, I wanted to use the margins and marginsplot commands. These are the commands that I suppose should work here:
margins border, dydx(open_courses_pc)
marginsplot
Unfortunately, Stata displays that the average marginal effect of an additional treatment unit is not estimable. Why is that? What can I do to make it work?
This is a subsample of the data that I use:
* Example generated by -dataex-. For more info, type help dataex
clear
input int(id year) float(depvar treat) byte border
16051 1992 5.659001 1.844677 0
16051 1993 5.969948 2.1201892 0
16051 1994 6.632103 2.0892866 0
16051 1995 7.364343 2.2689593 0
16051 1996 7.589586 2.517053 0
16051 1997 8.395014 2.2643163 0
16051 1998 8.724191 3.272064 0
16051 1999 8.344015 3.2046504 0
16051 2000 8.356103 3.086358 0
16051 2001 8.346075 4.09234 0
16051 2002 9.246387 3.680552 0
16052 1992 6.782907 1.9830587 0
16052 1993 6.954908 2.1813104 0
16052 1994 7.376133 2.3722627 0
16052 1995 7.389122 2.670767 0
16052 1996 8.284087 2.649389 0
16052 1997 9.655521 2.855218 0
16052 1998 9.71139 3.367119 0
16052 1999 8.391736 3.5564854 0
16052 2000 8.866537 3.792981 0
16052 2001 9.452379 3.847903 0
16052 2002 9.440229 4.006292 0
16053 1992 5.825078 2.3255873 0
16053 1993 4.916294 2.571731 0
16053 1994 5.657256 3.5029354 0
16053 1995 5.594696 4.3835344 0
16053 1996 6.872756 4.2879934 0
16053 1997 8.136395 5.61096 0
16053 1998 7.863774 6.014127 0
16053 1999 6.526358 6.674685 0
16053 2000 6.323956 7.328061 0
16053 2001 5.717675 7.334915 0
16053 2002 6.330813 7.141436 0
16054 1992 6.564031 2.651424 0
16054 1993 6.742497 4.1016374 0
16054 1994 6.612278 4.891504 0
16054 1995 6.689681 5.280836 0
16054 1996 6.847413 5.384323 0
16054 1997 8.840071 5.643429 0
16054 1998 8.433639 6.695895 0
16054 1999 7.683398 6.136964 0
16054 2000 8.394753 6.766604 0
16054 2001 8.159077 7.889673 0
16054 2002 8.560456 7.329383 0
16055 1992 5.296434 . 0
16055 1993 5.179822 4.6837664 0
16055 1994 5.66734 5.640367 0
16055 1995 6.633365 6.117193 0
16055 1996 6.116849 7.456423 0
16055 1997 7.052107 8.266324 0
16055 1998 7.358793 8.4082155 0
16055 1999 6.65012 9.335468 0
16055 2000 7.52683 9.706872 0
16055 2001 7.994332 9.792192 0
16055 2002 7.906977 8.990167 0
16056 1992 15.63072 1.0829372 1
16056 1993 15.624953 1.544871 1
16056 1994 14.44097 1.744424 1
16056 1995 17.719135 1.8106996 1
16056 1996 6.838715 2.3654954 1
16056 1997 7.466442 6.841046 1
16056 1998 6.804147 6.693712 1
16056 1999 7.114607 6.35955 1
16056 2000 7.20072 7.043204 1
16056 2001 6.546112 7.007233 1
16056 2002 7.077409 7.063868 1
16061 1992 7.848941 1.8201922 1
16061 1993 7.000764 2.0725389 1
16061 1994 7.118601 2.368622 1
16061 1995 6.193554 2.568246 1
16061 1996 7.047513 2.999487 1
16061 1997 7.664001 3.378901 1
16061 1998 7.261224 3.865488 1
16061 1999 6.533298 4.3235703 1
16061 2000 6.34826 3.899746 1
16061 2001 7.042229 3.852596 1
16061 2002 7.419556 3.5644445 1
16062 1992 6.183147 1.0003848 1
16062 1993 6.953912 1.2199845 1
16062 1994 8.828239 1.5525827 1
16062 1995 7.300481 1.4626485 1
16062 1996 7.934064 1.905044 1
16062 1997 9.055985 2.2334723 1
16062 1998 8.902207 2.8668466 1
16062 1999 8.604066 3.240741 1
16062 2000 8.596491 3.752155 1
16062 2001 9.468728 3.746545 1
16062 2002 9.737142 3.90148 1
16063 1992 15.63072 1.0829372 1
16063 1993 15.624953 1.544871 1
16063 1994 14.44097 1.744424 1
16063 1995 17.719135 1.8106996 1
16063 1996 6.83937 2.3657222 1
16063 1997 7.456942 1.3021363 1
16063 1998 6.424238 1.826733 1
16063 1999 6.476563 1.818681 1
16063 2000 6.311861 2.3707492 1
16063 2001 5.954055 2.443439 1
16063 2002 6.593969 2.468443 1
16064 1992 12.91089 1.890154 1
end
I tried many variations of the margins command, such as margins, dydx(open_courses_pc) at(border=(0 1)). Yet without any success. In the end, I managed to generate the desired plot by putting all relevant values in matrices, transforming those matrices into variables and then generating the desired plot based on these variables. However, I feel there should be an easier way. Does anyone have any idea about this?