I want to calculate a common set of statistics for each of number of subgroups, append the results to each other, and export them (e.g.) to an Excel worksheet. My attempts using -table- and -collect- have not been successful. Tips please.
Consider the following
Code:
. sysuse auto
(1978 automobile data)
. table (foreign), nformat(%3.2f ) stat(percent) stat( mean weight) nototals na
> me(c1)
-------------------------------------
| Percent Mean
| Weight (lbs.)
-----------+-------------------------
Car origin |
Domestic | 70.27 3317.12
Foreign | 29.73 2315.91
-------------------------------------
. table (rep78), nformat(%3.2f ) stat(percent) stat( mean weight) nototals name
> (c2)
---------------------------------------------
| Percent Mean
| Weight (lbs.)
-------------------+-------------------------
Repair record 1978 |
1 | 2.90 3100.00
2 | 11.59 3353.75
3 | 43.48 3299.00
4 | 26.09 2870.00
5 | 15.94 2322.73
---------------------------------------------
. collect preview, name(c1)
-------------------------------------
| Percent Mean
| Weight (lbs.)
-----------+-------------------------
Car origin |
Domestic | 70.27 3317.12
Foreign | 29.73 2315.91
-------------------------------------
. collect preview, name(c2)
---------------------------------------------
| Percent Mean
| Weight (lbs.)
-------------------+-------------------------
Repair record 1978 |
1 | 2.90 3100.00
2 | 11.59 3353.75
3 | 43.48 3299.00
4 | 26.09 2870.00
5 | 15.94 2322.73
---------------------------------------------
. collect combine newcoll = c1 c2
(current collection is newcoll)
. collect preview, name(newcoll)
-------------------------------------
| Percent Mean
| Weight (lbs.)
-----------+-------------------------
Car origin |
Domestic | 70.27 3317.12
Foreign | 29.73 2315.91
-------------------------------------
Something like:
Code:
-------------------------------------
| Percent Mean
| Weight (lbs.)
-----------+-------------------------
Car origin |
Domestic | 70.27 3317.12
Foreign | 29.73 2315.91
-------------------------------------
---------------------------------------------
| Percent Mean
| Weight (lbs.)
-------------------+-------------------------
Repair record 1978 |
1 | 2.90 3100.00
2 | 11.59 3353.75
3 | 43.48 3299.00
4 | 26.09 2870.00
5 | 15.94 2322.73
---------------------------------------------
Code:
-------------------------------------
| Percent Mean
| Weight (lbs.)
-----------+-------------------------
Car origin |
Domestic | 70.27 3317.12
Foreign | 29.73 2315.91
Repair record 1978 |
1 | 2.90 3100.00
2 | 11.59 3353.75
3 | 43.48 3299.00
4 | 26.09 2870.00
5 | 15.94 2322.73
---------------------------------------------
I've looked through the help and [TABLES], and may have missed something ...

Comment