Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
"statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Tabulate summary statistics by percentiles and save output |

Date |
Fri, 28 Dec 2012 17:59:21 +0000 |

Nick On 28 Dec 2012, at 11:43, annoporci <annoporci@gmail.com> wrote:

Dear Satalist, I wish to tabulate some summary statistics for some percentiles and toexport the tables to files in tex format. I have never done thatbefore. Ihave read the stata help about esttab, estpost, estout, tabout andtriedvarious things that failed. My best shot so far. Consider: sysuse ibm,clear tsset date local variables ibm spx /// Tabulate moments for different percentiles: foreach var of varlist `variables' { summarize `var' if inrange(`var',`=r(p1)',`=r(p10)'), detail summarize `var' if inrange(`var',`=r(p90)',`=r(p100)'), detail } The result is displayed in the Stata window. For reference: p1-p10: Obs = 493, Kurtosis = 5.05607 p90-p100: Obs = 50, Kurtosis = 3.619203 /// Export some summary satistics: foreach var of varlist `variables' {quietly estpost summarize `var' if inrange(`var',`=r(p1)',`=r(p10)'),detailesttab using moments`var'.tex, replace cells("count mean sdskewnesskurtosis") noobs nodis nonumbers nonotesquietly estpost summarize `var' if inrange(`var',`=r(p90)',`=r(p100)'),detailesttab using moments`var'.tex, append cells("count mean sdskewnesskurtosis") noobs nodis nonumbers nonotes } There are two issues: one about the display, one about the data.1) FIRST issue: my code creates two separate tables stacked on topof eachother. I would like instead that the second round of data for count,mean,sd, skewness, kurtosis be "inserted" into the first table just belowthefirst round of data, something like:& count& mean& sd&skewness&kurtosis\\ \hline ibm, p1-p10 & 493& .0461508& 1.231737& .144965& 5.05607\\ ibm, p90-p100 & 493& .0461508& 1.231737& .144965& 5.05607\\2) SECOND issue: my loop is not correctly selecting the percentiles.As youcan see, the results for the two parts of the loop are identical.In fact, the very first loop reported above is also incorrect. Thetotalnumber of observations in the dataset is 493, so p1-p10 should havefewerthan that and not 493 as reported. I have tried playing around with preserve/restore, I have also tried inserting "use ibm,replace" at various stages inside the loops, but couldn't work it out.I may be approaching this from the wrong angle. Any suggestions willbemuch appreciated. Thanks. Patrick Toche

* * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: Re: Re: st: Tabulate summary statistics by percentiles and save output***From:*annoporci <annoporci@gmail.com>

**Re: Re: st: Tabulate summary statistics by percentiles and save output***From:*annoporci <annoporci@gmail.com>

**References**:**st: Tabulate summary statistics by percentiles and save output***From:*annoporci <annoporci@gmail.com>

- Prev by Date:
**st: Question Time varying parameters (Master thesis Marketing Research)** - Next by Date:
**st: ivreg2 update** - Previous by thread:
**st: Tabulate summary statistics by percentiles and save output** - Next by thread:
**Re: Re: st: Tabulate summary statistics by percentiles and save output** - Index(es):