Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: R�p. : st: RE: formatting and exporting ttest results

From   "Akihito Tokuhara" <[email protected]>
To   [email protected]
Subject   RE: st: RE: R�p. : st: RE: formatting and exporting ttest results
Date   Fri, 14 Apr 2006 10:03:54 -0500

Dear Ina,

As others have given advice on commands for t-test, my reply here is about how to export or
write out to a text *.txt file with user-made formats suitable for different objective, which I don't
know if that is what Ina's question is about. You can use the command -- file write -- like this:

file open anyname using myresult.txt, write text append/replace;
file write anyname _newline _col(18) " <**>> stuffs here <<**> " _newline;
file write anyname _newline _col(4) " ** others ** " _newline;
file close anyname;

The command -- file write -- is like -- display --, and you have to test the output text file until you
get the format you want. I often have to use this to get the format I need for converting to
different forms of tables. Sometimes you may need to create temporary variables to save the
results for the writing out to text file. I am not sure if this is what Ina asked about. HTMH.



From: "Newson, Roger B" <[email protected]>
Reply-To: [email protected]
To: <[email protected]>
Subject: st: RE: R�p. : st: RE: formatting and exporting ttest results
Date: Wed, 12 Apr 2006 16:36:11 +0100

Another possibility for saving t-test results (although not a short one) is to use -regress- together with -parmby- and -metaparm-. This has the advantage that -metaparm- uses the Satterthwaite corrected degrees of freedom, so the confidence limits will be robust to heteroskedasticity between the two groups compared.

For instance:

sysuse auto, clear
parmby "regress weight, robust", by(foreign) norestore
tempfile tf1
metaparm [iweight=!foreign-foreign], saving(`tf1', replace)
append using `tf1'

will produce and display a dataset in memory (overwriting the original -auto- data), with 1 observation for each of 3 parameters (mean US car weight, mean non-US car weight, and their difference). These results will be essentially the same as those produced by the shorter program

sysuse auto, clear
ttest weight, by(foreign) unequal

However, the results produced by -parmby- and -metaparm- can be tabulated and/or plotted as the user desires. This is an example of the resultsset approach to plotting and tabulating results, and more references on this can be found in the online help for the -parmest- package (which includes -parmby-). Both -parmby- and -metaparm- can be downloaded from SSC using the -ssc- command in Stata.

I hope this helps.


Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute at Imperial College London
St Mary's Campus
Norfolk Place
London W2 1PG
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute at Imperial College London
47 Praed Street
London W1 1NR
TELEPHONE: (+44) 020 7594 0939
FAX: (+44) 020 7594 0942
EMAIL: [email protected]
Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Herve STOLOWY
Sent: 12 April 2006 16:02
To: [email protected]
Subject: R�p. : st: RE: formatting and exporting ttest results

Dear Ina:

Sorry, I did not see your first posting. I just discovered Nick's reply. Some time ago, I raised the same issue and received several replies which helped to find a solution. But this solution, as Nick said, is not a "short answer".

If you make a ttest with a groupvar, you can use -statsmat- and -makematrix- (downloadable from ssc)(with -ttest-) followed by -mat2txt- (downloadable from ssc) to get a .txt file.

Here is an example I used for one research project:

statsmat size1, s(N mean sd) by(format_bs) mat(mat1)
makematrix mat2, from(r(t) r(p)) label : ttest size1, by(format_bs)
matrix mat3=mat2' //Transposition of the matrix
matrix mat4 = mat1, mat3 // Grouping of the two matrices
matrix colnames mat4 = "Number of observations" Mean "Standard deviation" "Student t-test"
mat2txt, matrix(mat4) saving(univariate_bs) replace

If you want to compare two variables with a ttest, here is another example and solution:

makematrix T5A1, from(r(N) r(mean) r(sd) r(min) r(p50) r(max)) label : univar MAPE_direct_scal MAPE_indirect_scal if outlier_cfo_scal!=1 &outlier_MAPE!=1
ttest MAPE_direct_scal = MAPE_indirect_scal if outlier_cfo_scal!=1 &outlier_MAPE!=1
mat T5A2 = r(p) \ r(t)
mat T5A3 = T5A1, T5A2
matrix colnames T5A3 = N "Mean" "Std Dev" "Min" "Median" "Max" "T/p-value"
mat2txt, matrix(T5A3) saving(stat_MAPE_table5A) replace

The syntax might not the most effective but I know these commands work.

I hope this helps.

Best regards

Herv� Stolowy
Coordinateur du D�partement/Head of Department
HEC Paris
D�partement Comptabilit� Contr�le de gestion / Dept of Accounting and Management Control
1, rue de la Liberation
78351 - Jouy-en-Josas
Tel: +33 1 39 67 94 42 - Fax: +33 1 39 67 70 86
[email protected]
>>> [email protected] 12/04/06 13:50 >>>
The short answer is: Evidently not.

However, as a t-test comparing two group means
is really a regression in disguise, you
should be able to use your favourite post-regression
program for this purpose.

[email protected]

Ina Ganguli

> I was wondering whether there is a command (like -outreg-) I can use
> to format and export multiple -ttest- results to a .txt file for
> easier conversion to tables?
> I would like to have results in the following format:
> Group1 Group2 Difference
> variable1 mean mean mean*
> (se) (se) (se)
> variable2 mean mean mean*
> (se) (se) (se)
> etc.
> I've seen references to commands that may perhaps be what I need
> (-tabexport-, -parmby-?), but I wanted to check whether there is a
> program/command out there that would work well for this.

* For searches and help try:

* For searches and help try:

* For searches and help try:
Express yourself instantly with MSN Messenger! Download today - it's FREE!

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index