Hello,
I am estimating an outcome variable (called it DV) using the -ivreg2- command in Stata on panel data. Following the literature, I have two endogenous variables (call them EV1 EV2) and two instruments (call them IV1 IV2) plus several controls (call them Var1...). I am trying to show visually the 1. the coefficients and standard errors of the two endogenous variables and 2. at different lags. So I run multiple models with different lags, save them, and plot them using Coefplot. I can plot both the endogenous variables over time almost like I want. The problem I'm having is that I would like to have a legend in Coefplot to label each endogenous variable so the reader can easily compare their different effects across time. Since they are part of the same model that I save, however, I don't know how to make this work
This is what my code looks like in a simplified way:
My coefplot command looks something like this:
I am estimating an outcome variable (called it DV) using the -ivreg2- command in Stata on panel data. Following the literature, I have two endogenous variables (call them EV1 EV2) and two instruments (call them IV1 IV2) plus several controls (call them Var1...). I am trying to show visually the 1. the coefficients and standard errors of the two endogenous variables and 2. at different lags. So I run multiple models with different lags, save them, and plot them using Coefplot. I can plot both the endogenous variables over time almost like I want. The problem I'm having is that I would like to have a legend in Coefplot to label each endogenous variable so the reader can easily compare their different effects across time. Since they are part of the same model that I save, however, I don't know how to make this work
This is what my code looks like in a simplified way:
Code:
xi: xtivreg2 DV l1.var1 l1. var2 (l1.EV1 l1.EV2 = l1.IV1 l1.IV2), fe cl(country_ID)
eststo model1
xi: xtivreg2 DV l2.var1 l2. var2 (l2.EV1 l2.EV2 = l2.IV1 l2.IV2), fe cl(country_ID)
eststo model2
xi: xtivreg2 DV l3.var1 l3. var2 (l3.EV1 l3.EV2 = l3.IV1 l3.IV2), fe cl(country_ID)
eststo model3
Code:
coefplot (eststo model1) ///
(eststo model2) ///
(eststo model3) ///
keep(l1.EV1 l1.EV2 ///
l2.EV1 l2.EV2 ///
l3.EV1 l3.EV2) ///
coeflabels(1. l1.EV1 = " Lag 1" ///
2.l1.EV2 = " " ///
3. l2.EV1 = " Lag 2" ///
4. l2.EV2 = " " ///
5. l3.EV1 = " Lag 3" ///
6. l3.EV2 = " " ) ///
yline(0) vertical ///
mlabel (cond(@pval<.001, "***", ///
cond(@pval<.01, "**", ///
cond(@pval<.05, "*", ///
cond(@pval<.1, "+", ""))))) ///
baselevels ytitle("Estimated Outcome") ///
mlabsize(large) ///
graphregion(color(white)) bgcolor(white)
