Announcement

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

  • Exporting the Weighted Mean of the Dependent Variable into an Outreg2 Regression Table

    Hello,

    I am currently trying to export my regressions into a table using the user-written outreg2 in Stata 17 and want to add the mean of my dependent variable to the bottom of my regression table. I've tried the two following approaches and I am not sure quite how to fix it. I am also using the user-written reghdfe to run my regressions.
    The first approach:
    Code:
    reghdfe ca_inwork precovidhealth female ca_age ca_age2 ca_age3 ca_age4 precovidhours precovidhours2 precovidwantsjob precovidlooksforjob precovidnonwhite precovidarsinhwage $precovideducation if ca_age>=25&ca_age<65 [pweight=ca_betaindin_xw_t], absorb(precovidyearlastjob precovidjbstat precovideprosh precovidscsf4a precovidscsf4b precovidscsf5 precovidoccupation precovidindustry) vce(robust)
    outreg2 using table1, replace word dec(3) nocons keep(precovidhealth) label ctitle(Apr. 2020) stats(coef se mean)
    I believe this is not working as outreg2 does not support pweights for summary statistics, although when I tried aweights my table came out without any mean statistic,

    My next approach was to try and save the summary statistic from the regression command, which stores the weighted means of the statistics in e(summarize) and I try to call the relevant result using a macro.
    Code:
    reghdfe ca_inwork precovidhealth female ca_age ca_age2 ca_age3 ca_age4 precovidhours precovidhours2 precovidwantsjob precovidlooksforjob precovidnonwhite precovidarsinhwage $precovideducation if ca_age>=25&ca_age<65 [pweight=ca_betaindin_xw_t], absorb(precovidyearlastjob precovidjbstat precovideprosh precovidscsf4a precovidscsf4b precovidscsf5 precovidoccupation precovidindustry) vce(robust) summarize(mean)
    outreg2 using table1, replace word dec(3) nocons keep(precovidhealth) label ctitle(Apr. 2020) addtext(Mean, `e(summarize)[1,1]')
    This just ignores the e(summarize)[1,1] (which is where the statistic I want is stored) and it just reports "matrix" in the cell where I want to see the summary statistic.
    I am not sure of what else to try and I do not want to have to manually input this statistic by hand into dozens of table columns.
    I will be very appreciative of any help. Thank you.

  • #2
    Code:
    use auto, clear
    summ price
    local mp: di %6.1f r(mean)
    reghdfe price weight mpg, absorb(rep78)
    outreg2 using table1, replace word dec(3) nocons label ctitle(Apr. 2020) addtext(Mean, `mp')
    outreg2 using table2, replace word dec(3) nocons label ctitle(Apr. 2020) addstat(Mean, `mp')

    Comment


    • #3
      Originally posted by George Ford View Post
      Code:
      use auto, clear
      summ price
      local mp: di %6.1f r(mean)
      reghdfe price weight mpg, absorb(rep78)
      outreg2 using table1, replace word dec(3) nocons label ctitle(Apr. 2020) addtext(Mean, `mp')
      outreg2 using table2, replace word dec(3) nocons label ctitle(Apr. 2020) addstat(Mean, `mp')
      Thank you; tweaking this was able solve my problem.

      Comment

      Working...
      X