Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plotting dependent variable mean besides coefficients using esttab

    I am using the user-written esttab command from SSC to generate table output. I am trying to plot a regression coefficient and standard error, and the mean of the dependent variable in the column beside it. Unfortunately, none of the solutions I could come up with produce the output I am looking for.

    In principle, this produces the desired output. But it also plots a standard error and significant stars for the dependent variable mean, which I want to omit.
    Code:
    sysuse auto, clear
    eststo: reg price mpg
    eststo: mean price if e(sample)
    esttab, keep(mpg) ren(price mpg)
    This plots the dependent variable mean in another row, and renaming it produces an error:
    Code:
    sysuse auto, clear
    eststo: reg price mpg
    sum price if e(sample), meanonly 
    estadd mat ymean=r(mean)
    esttab, cell("b ymean" "se")  
    esttab, cell("b ymean" "se") ren(c1 mpg) keep(mpg)
    This solution would work as well but the cell command does not recognize the r(mean) from using estadd ysumm:
    Code:
    sysuse auto, clear
    eststo: reg price mpg
    estadd ysumm
    esttab, cell("b ymean" "se") keep(mpg)
    Any help would be much appreciated.

  • #2
    Thanks for the data example. It is tricky asking for different formatting across models. The following uses estadd which should come compiled with your estout installation. If not

    Code:
    ssc install estadd, replace
    Code:
    sysuse auto, clear
    qui reg price mpg
    qui mean `e(depvar)' if e(sample)
    local mean = _b[`e(varlist)']
    eststo m1: reg price mpg
    mat mean=e(b)
    mat mean[1,1]= `mean'
    estadd matrix mean= mean
    esttab, cells((b(star) mean) se(par)) keep(mpg) mlab(none) nonum collab("Price" "Mean")
    Res.:

    Code:
    . esttab, cells((b(star) mean) se(par)) keep(mpg) mlab(none) nonum collab("Price" "Mean")
    
    -----------------------------------------
                        Price            Mean
    -----------------------------------------
    mpg             -238.8943***     6165.257
                   (53.07669)                
    -----------------------------------------
    N                      74                
    -----------------------------------------
    Last edited by Andrew Musau; 02 Jul 2021, 09:48.

    Comment


    • #3
      Hi Andrew,

      Amazing, thank you so much. Minor note: in my implementation I saved the model in the first regression and used
      Code:
      est store m1
      to get the results back.

      Code:
      sysuse auto, clear 
      eststo m1: qui reg price mpg
      qui mean `e(depvar)' if e(sample)
      local mean = _b[`e(varlist)']
      est restore m1
      mat mean=e(b)
      mat mean[1,1]= `mean'
      estadd matrix mean= mean
      esttab, cells((b(star) mean) se(par)) keep(mpg) mlab(none) nonum collab("Price" "Mean")
      This is just to minimize the potential for errors.

      Thanks a million again.

      Comment

      Working...
      X