Announcement

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

  • Show SD-within statistics from panel data via outreg2 descriptive table

    Dear Statalist,

    For my Masters I need to replicate a paper using Stata. I have managed to successfully merge all my data to a similar dataset as used in the paper which I need to replicate. This dataset contains monthly panel data containing 2,300 firms and 84 months resulting in almost 150k observations. But at the moment I'm struggling to replicate the descriptives tables which shows, next to common statistics as the mean SD and median, the SD within firms.
    Via outreg2 I have created a descriptive table containing all other statistics except the SD within. I have tried to add these statics using the following methods without any useful result.

    Code:
    xtsum varlist
    outreg2 using Meeting1.doco, replace sum(detail) keep(varlist) eqkeep(mean p50 sd p1 p99 N sd_w) see label
    Code:
    xtsum varlist
    outreg2 using Meeting1.doco, replace sum(detail) keep(varlist) eqkeep(mean p50 sd p1 p99 N) addstat(SD within, e(r(sd_w)) see label
    Code:
    xtsum varlist
    outreg2 using Meeting1.doco, replace sum(detail) keep(varlist) eqkeep(mean p50 sd p1 p99 N) e(r(sd_w) see label
    Could somebody please explain which commands I need to overcome this problem?

    If something is not clear please explain to my what I need to change in my explanation.

    Many thanks in advance!

  • #2
    You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters (which you do), readable Stata output (fixed spacing fonts help), and sample data using dataex. Being able to replicate your problem helps us help you.

    After any Stata command, issue returns list, ereturns list, and sreturns list to see what the command has saved. xtsum saves the within standard deviation in r(sd_w) So you can use the added statistics capability in outreg2 to add this. I suspect your addstat statement would work if you replace e(r(sd_w)) with r(sd_w).

    Comment


    • #3
      I suspect your addstat statement would work if you replace e(r(sd_w)) with r(sd_w).
      I agree.

      Here's how I added some additional stats after a clogit regression (but because it's a regression, Stata stores them in e(). For descriptive stats, Stata stores them in r()
      Code:
      addstat(Pseudo-R: , e(r2_p), Log like:, e(ll_0), Wald Chi-square:, e(chi2), Prob Wald:, e(p), Number clusters:, e(N_clust))

      Note however: I often have trouble using outreg2 for descriptive statistics, so I use logout and mkcorr (both from SSC) for those:

      Code:
      logout, save(`tab_table') excel replace: tabstat `rhsvars' if sample==1, stats(n mean median p25 p75 min max) col(stats)
      corr    `rhsvars' if sample==1, means
      mkcorr  `rhsvars' if sample==1, replace means log(`log_file') num cdec(3)  /* Creates txt file that can be imported in Excel */
      * "means" option means summ (so "n mean sd min max"); NUM option means "number the variables & put across the top"
      Tabout (ssc install tabout) is also really good, and has an excellent tutorial here

      Hope that help!
      --David
      Last edited by David Benson; 13 Feb 2019, 13:29.

      Comment

      Working...
      X