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
[email protected]
[email protected]
> 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/