Reputation: 1
I have two 95% confidence intervals I would like to display side by side in one coeff plot in Stata.
The first is just a regression that I run, and I use coefplot
to plot the coefficient & its 95% confidence interval.
The second, though, is not a regression. I just have a variable for a coefficient value and a variable for its standard error. I would like to hard code that coefficient & SE and make coefplot
display that value. Or run a "dumb" regression using the coefficient & SE that displays a coefficient such that I can plot out that second 95% confidence interval.
Anyone know how to do this?
I tried looking things up a lot and trying some regressions, but haven't found a way to hardcode it yet.
Upvotes: 0
Views: 878
Reputation: 589
You can do this with ereturn post
. Here's an example. I rename the variable "gear" to "HAND_CODED_COEF" to make clear that's the one I'm messing with. I'm able to change the coefficient and its standard error. (Note this uses the coefplot package available on SSC.)
sysuse auto, clear
rename gear HAND_CODED_COEF
regress mpg price weight head HAND_CODED_COEF
* Edit coefficient matrix
mat my_b = e(b)
mat my_b[1,4] = 15
* Edit variance matrix
mat my_V = e(V)
mat my_V[4,4] = 2.2
* Write to saved estimates
ereturn post my_b my_V
* Show that matrices have been changed
mat list e(b)
mat list e(V)
* coefplot shows the hand-edited values!
coefplot , nolabel drop(_cons)
Here's what the coefplot command gets you:
And in case it better answers the question here's code for having one real regression (m1) and one nonsense regression where you edit things (m2). Edit I also explain how to edit the point estimate and confidence interval for the constant term specifically, and I add an xline to the coefplot showing that the confidence interval is as expected.
sysuse auto, clear
rename gear HAND_CODED_COEF
eststo m1: regress mpg foreign
* Fake regression
regress mpg HAND_CODED_COEF
* Edit coefficient matrix
mat my_b = e(b)
***** The constant estimate is in the 1st row, 2nd column of e(b)
***** see the mat list command:
mat list my_b
* We will set it to -88
mat my_b[1,2] = -88
* Edit variance matrix
mat my_V = e(V)
***** The variance term for the constant is in the
***** bottom right cell of the matrix:
mat list my_V
* We will set the variance to 100,
* so that the standard error will be 10,
* and the lower part of the 95% confidence interval will be
* (-88 - 1.96*10)
mat my_V[2,2] = 100
* Write to saved estimates
ereturn post my_b my_V
eststo m2
* Show that matrices have been changed
mat list e(b)
mat list e(V)
* coefplot shows the hand-edited values for m2!
* The xline shows that the confidence interval
* is exactly where we wanted
coefplot m1 m2 , nolabel xline(`= -88 - 1.96*10')
Upvotes: 1