Statalist The Stata Listserver


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

st: RE: saving tabstat results


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: saving tabstat results
Date   Thu, 4 May 2006 18:02:48 +0100

On the last detail, note that -tabexport- 
is not a wrapper for -tabstat-. It is 
a wrapper for -collapse-, as the help 
emphasises. 

-tabstat- and -collapse- have different views 
on aweights. 

. sysuse auto, clear 

. tabstat mpg [aweight=w], by(foreign) stats(sum) 

Summary for variables: mpg
     by categories of: foreign (Car type)

 foreign |       sum
---------+----------
Domestic |   3272600
 Foreign |   1221120
---------+----------
   Total |   4493720
--------------------

. tabexport mpg [aweight=w] using results.txt , s(sum) by(foreign) replace

     +-----------------------------+
     |  foreign   _stats       mpg |
     |-----------------------------|
  1. | Domestic      sum    986.58 |
  2. |  Foreign      sum   527.275 |
     +-----------------------------+

. collapse (sum) mpg [aweight=w] , by(foreign)

. l

     +--------------------+
     |  foreign       mpg |
     |--------------------|
  1. | Domestic    986.58 |
  2. |  Foreign   527.275 |
     +--------------------+

Exporting -tabstat- results is a little tricky. 
You need to get the results into a matrix 
and then that matrix into a file. 

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

Samu.Kurri@bof.fi
 
> I need to calculate weighted sums of histograms, using aweights. There
> are around 650 of them, and each of them has data values (h) 
> from  -100
> to +100 (x). The weights w reflect the group weights.
> 
> The way how I managed to do it easily is to use tabstat ( tabstat
> h[aweight=w], by(x) stats(sum) )
> 
> But how can I save the results efficiently as an independent file?
> 
> I tried to use the save command with tabstat ( tabstat h[aweight=w],
> by(x) stats(sum) save ) but have can I retrieve the results and/or
> export them.
> 
> I also tried tabexport (SSC-file) but for some reason the results from
> line ( tabexport h[aweight=w] using results.txt , s(sum) by(x)  )
> difffer from the tabstat command.

*
*   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