regsave and coefplot are two commands that help plot coefficients from a regression.
Check out this worksheet that TA’s created as well!
Coefplot
First, install the command and browse the help file to understand the syntax of the command
ssc install coefplot, replace
help coefplotNow, let’s open some data and play with it
So, the command coefplot should have produce the graph above. Notice what’s happening, it’s plotting the betas (those are the dots) and the confidence interval, notice that the coefficient on price looks so small and close to zero, (1) because it is really small, but (2) because relative to the constant, it’s very small, so having the constant there changes the scale of the graph. Let’s drop the constant or let’s keep the price coefficient either should work
coefplot, keep(price)
coefplot, drop(_cons)Now, we can notice the coefficient and the confidence intervals, and noticed that it is not statistically significant (presumably also not economically significant, this is not surprising because this represent a dollar increase, if we want to understand a more real change we would want to multiply this coefficient by say $5,000, which would imply a decrease of 4.6 mpg.
In any case, now let’s say we want to change the orientation of this coefficient, we would use the option vertical
coefplot, keep(price) verticalGreat, now let’s change the y-label so that it includes a 0, I personally like symmetry around 0 for graphs, so let’s do that
coefplot, keep(price) vertical ylabel(-0.002(0.001)0.002)Great, now let’s add a line around 0 so that is more visible that this coefficient is statistically significant
coefplot, keep(price) vertical ylabel(-0.002(0.001)0.002) yline(0)Awesome! Now we’ve used this graph to plot a coefficient from the regression. Now imagine the regression has more than one coefficient
reg mpg price foreign weight
coefplot, drop(_cons) vertical yline(0)So in this manner we can plot all the coefficients (minus the constant), remember you can either drop a variable/s or keep a number of variables. For an event-study, we’ll want to keep only the coefficients on the interaction.
Regsave
regsave works a bit different from coefplot, what coefplot was doing is plotting the coefficients straight up. What regsave does, is saves the results from the regression in a whole new dta. Why is this useful? Well because then, we can open that dataset where the coefficients have been save and graph them using “twoway” which we’ve learned before.
Ok, great! But we need to drop the constant, in my case the constant takes the value of 1. The other thing is the labels! so let’s make both changes
twoway (scatter coef variables, sort) if variables>1, xlabel(, valuelabel)- Don’t love the”2.5” and the “3.5” so will change the ticks for the x-axis
- Don’t also love the title of “variable” so i’m going to change that to blank.
twoway (scatter coef variables, sort) if variables>1, xtitle(" ") xlabel(2(1)4, valuelabel)So the only thing left, is the confidence interval, so let’s add that into the dta, but for that we need to run the regression again, and add the option “ci” for regsave part
sysuse auto, clear
* We run the reg
reg mpg price foreign weight
* And now save it using regsave
regsave using "$hw/test.dta", replace ci
* Now open the data
use "$hw/test.dta", clear
encode var, gen(variables)
twoway (scatter coef variables, sort) if variables>1, xtitle(" ") xlabel(2(1)4, valuelabel)Ok so this creates the same graph as above, but not let’s add the CIs
twoway (scatter coef variables, sort) ///
(rcap ci_lower ci_upper variables, sort) ///
if variables>1, xtitle(" ") xlabel(2(2)1, valuelabel)ok the legend is too big! let’s turn that off
twoway (scatter coef variables, sort) (rcap ci_lower ci_upper variables, sort) if variables>1, xtitle(" ") xlabel(2(1)4, valuelabel) legend(off) Great, so that we have a similar graph! For the event studies instead of using scatter you may want to use connected or line.