2

I am using the coefplot command in Stata to plot coefficients and confidence intervals from multiple regression models. I am plotting the same coefficient (X) from 4 different model specifications.

There is one model specification (alternative standard errors) that I cannot figure out how to estimate in Stata, but am able to estimate using R. That means that for one model specification, I have the standard error in R, but not in Stata.

Is there an easy way to manually alter the standard errors in coefplot?

My code is:

coefplot A B C D, drop(_cons) xline(0) keep(X)

How can I add to this code that the standard errors for coefficient X in model D should be Z?

Nick Cox
  • 35,529
  • 6
  • 31
  • 47
user1288578
  • 411
  • 1
  • 6
  • 15
  • 2
    Might I ask what kind of "alternative standard errors" you are using? – JR96 Apr 28 '21 at 20:30
  • 1
    An alternative work-around is to combine a `rcap` plot and a `scatter` plot using `twoway` to produce a plot similar to that produced by `coefplot`. The downside is that you may need to manually specify the desired coefficients and upper and lower bounds using `input`. Happy to provide an example if that would be useful to you. – Bicep Apr 29 '21 at 04:19
  • Coefplot has `se` and `ci` options where it appears that you can create a matrix with ci's / se's and use that as an input instead of the default `e(V)`. – Wouter Apr 29 '21 at 07:13

1 Answers1

3

You can manually edit the e(V) (variance-covariance matrix) and e(b) vectors. For this, define a program:

est restore estimates1

 capture program drop changeeV
 program changeeV, eclass
   tempname b V 
   matrix `b' = e(b)
   matrix `V' = e(V)
   matrix `V'[1,1] = 1.1 // Add values of new variance-covariance matrix
   matrix `b'[1,1] = 10 // Add new coefficient vector
   ereturn post `b' `V' // Repost new vectors 
   ereturn local cmd "reg outcome treatment covariates"
          // Repost initial command (required)
 end
changeeV // Execute program

est store eaX  // Store new generated estimtes

Note that, to reach the covariance matrix, you need to take the square of the standard errors from your output in R. Good luck!

Jonathan Old
  • 311
  • 1
  • 5
  • Thanks, Jonathan! I trust that this would work, but is still a little over my head. I found a reasonable solution, using ci(Y) I had Stata plot extra large confidence intervals (97.5% instead of 95%) so that the plotted Stata confidence interval matches the 95% confidence interval estimated with R. Not exact, but close enough for the plot I am making. – user1288578 May 01 '21 at 17:42