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

Re: st: Output table with means pvalues for difference in means

 From John Luke Gallup To statalist@hsphsun2.harvard.edu Subject Re: st: Output table with means pvalues for difference in means Date Fri, 15 Jun 2012 14:34:31 -0700

```Quinn,

If you put the results you want into a Stata matrix, you can use the program -frmttable- (userwritten, by me, at SSC) to convert this to a formatted Word or TeX table.

The following example creates a table like the one you describe:

sysuse auto, clear
mat T = J(2,4,.)

ttest mpg, by(foreign)
mat T[1,1] = r(mu_1)
mat T[1,2] = r(mu_2)
mat T[1,3] = r(mu_1) - r(mu_2)
mat T[1,4] = r(p)

ttest weight, by(foreign)
mat T[2,1] = r(mu_1)
mat T[2,2] = r(mu_2)
mat T[2,3] = r(mu_1) - r(mu_2)
mat T[2,4] = r(p)
mat rownames T = mpg weight

frmttable using ttest.doc, statmat(T) varlabels replace ///
ctitle("", Sample1mean, Sample1mean, Difference, "(p-value)")

The -frmttable- command displays the table below and saves it to the Word file ttest.doc:

------------------------------------------------------------------
Sample1mean  Sample1mean  Difference  (p-value)
------------------------------------------------------------------
Mileage (mpg)      19.83        24.77       -4.95       0.00
Weight (lbs.)    3,317.12     2,315.91     1,001.21     0.00
------------------------------------------------------------------

If you want to get fancy, you can change fonts and other formatting, as well as merge or append this table with new results.

John

On Jun 13, 2012, at 10:32 AM, Swanquist, Quinn Thomas wrote:

> Statalisters,
>
> I am trying to output a table (into txt, word, or excel) that shows the means for variables in two subsamples as well as the pvalue from the ttest of difference in means. Is there a command similar to outreg2 that will do this.
>
> At the end of the day this is how I need the data to look:
>
> 	Sample1mean	 Sample2mean	 Difference 	 (p-value)
> v2 	 0.0903		 0.0994 		 (0.0091)	0.00
> v1	 145.9465	 66.3245 	 79.6220 	0.00
>
> Quinn Swanquist
> qswanqui@utk.edu
>
>
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
> Sent: Wednesday, June 13, 2012 1:09 PM
> To: 'statalist@hsphsun2.harvard.edu'
> Subject: st: RE: Syntax for trimming distribution tail In xtabond2
>
> There is no context here. But even assuming that r(p1) and r(p99) are available from some previous command, the quote characters here are incorrect -- you would need left single quotes as opening delimiters -- and one parenthesis is unmatched.
>
> ... if inrange(y, `r(p1)',`r(p99)')
>
> is more likely to be what you have in mind.
>
> This is not to be construed as supporting trimming distribution tails, in my view a horrible method.
>
> Nick
> n.j.cox@durham.ac.uk
>
> Jason Hecht
>
> Apparently the following syntax that worked in xtabond did not work in xtabond2:
>
> xtabond y l.x1 l.x2 l.x3 if inrange(y, 'r(p1','r(p99)'), noconstant
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

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