Statalist The Stata Listserver


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

st: -tabexport- available from SSC


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: -tabexport- available from SSC
Date   Fri, 7 Apr 2006 00:39:39 +0100

Thanks to Kit Baum, a new program -tabexport- is 
downloadable from SSC. Stata 8.2 is required. 

On 30 March, "Venable", later revealed to be 
Raymond Guiteras, started a thread: 

---------------------------------- post from Venable 
I use Stata 8.2 for Windows. I would like to export results from
tabstat to .txt files. The format in the Stata Results window, with
the statistics "stacked" over each other, is almost perfect (if I
could put standard deviations in parentheses, that would be perfect),
but copying and pasting is time-consuming and could lead to errors,
plus it makes replication difficult.

The sort of tabstat command I would like to export is

tabstat wheat corn barley, stat(mean sd) by(year) save

I have tried -statsmat- and -tabstatmat-, but neither seems to work
quite right for what I want to do:

[...] 

I have also tried the -tablemat- command but this allows only one statistic.

The closest thing for what I would like to do seems to be -latabstat-,
which exports beautifully to LaTeX tables - is there something similar
for text files?
--------------------------------- 

I replied, pointing that this was an inappropriate problem
for -statsmat- (authors: Kit Baum, myself) and for -tabstatmat- (myself), 
which both concern single matrices only. (The same applies to -tablemat-, 
author Amadou Diallo, which further is restricted to a single statistic.) 

In that and subsequent postings, I played around with a program 
I called -mytabstatexport-. I got fed up with my own name, 
and in any case it might be understood to be an add-on to 
-tabstat-, which it is not. 

-tabexport- is indicative of another approach, not definitive. The main
idea is just 

	preserve 
	collapse 
	(reshape)
	outfile | outsheet
	restore 

and experienced users will be able to do that for themselves faster than they 
can figure out how to use -tabexport-. 

Be that as it may, here is a taste: 

. sysuse auto, clear
(1978 Automobile Data)

. tabexport turn trunk length using results.txt, s(mean sd) by(foreign)

     +-------------------------------------------------+
     |  foreign   _stats      turn     trunk    length |
     |-------------------------------------------------|
  1. | Domestic     mean   41.4423     14.75   196.135 |
  2. | Domestic       sd   3.96758   4.30629   20.0461 |
  3. |  Foreign     mean   35.4091   11.4091   168.545 |
  4. |  Foreign       sd   1.50108   3.21691   13.6825 |
     +-------------------------------------------------+

. tabexport turn trunk length using results.txt, s(mean sd) by(foreign) total replace

     +-------------------------------------------------+
     |  foreign   _stats      turn     trunk    length |
     |-------------------------------------------------|
  1. | Domestic     mean   41.4423     14.75   196.135 |
  2. | Domestic       sd   3.96758   4.30629   20.0461 |
  3. |  Foreign     mean   35.4091   11.4091   168.545 |
  4. |  Foreign       sd   1.50108   3.21691   13.6825 |
     +-------------------------------------------------+

     +----------------------------------------------+
     |         _stats      turn     trunk    length |
     |----------------------------------------------|
  1. | Total     mean   39.6486   13.7568   187.932 |
  2. | Total       sd   4.39935    4.2774   22.2663 |
     +----------------------------------------------+

. tabexport turn trunk length using results.txt, s(mean sd) by(foreign) total replace outsheet

     +-------------------------------------------------+
     |  foreign   _stats      turn     trunk    length |
     |-------------------------------------------------|
  1. | Domestic     mean   41.4423     14.75   196.135 |
  2. | Domestic       sd   3.96758   4.30629   20.0461 |
  3. |  Foreign     mean   35.4091   11.4091   168.545 |
  4. |  Foreign       sd   1.50108   3.21691   13.6825 |
     +-------------------------------------------------+

     +----------------------------------------------+
     |         _stats      turn     trunk    length |
     |----------------------------------------------|
  1. | Total     mean   39.6486   13.7568   187.932 |
  2. | Total       sd   4.39935    4.2774   22.2663 |
     +----------------------------------------------+

. type results.txt
foreign _stats  turn    trunk   length
"Domestic"      "mean"  41.4423 14.75   196.135
"Domestic"      "sd"    3.96758 4.30629 20.0461
"Foreign"       "mean"  35.4091 11.4091 168.545
"Foreign"       "sd"    1.50108 3.21691 13.6825
"Total" "mean"  39.6486 13.7568 187.932
"Total" "sd"    4.39935 4.2774  22.2663

In short, -tabexport- can send a one-, two- or three-dimensional 
array of summary statistics to an external file using -outfile- 
or -outsheet-. The arrays are created by -collapse-, although 
-tabexport- can't emulate everything done by -collapse-. What 
you see echoed are -list-s of what is sent to the file, either
as one part or as two. 

Nick 
n.j.cox@durham.ac.uk 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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