Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: Collecting Statistics of Averages of Variables

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: Collecting Statistics of Averages of Variables Date Fri, 28 Sep 2012 19:24:15 +0100

```Check out -statsby-.

Nick

On 28 Sep 2012, at 18:55, robert hartman <rohartman@gmail.com> wrote:

```
```Hi Listers,
I'm struggling with a couple of programming challenges. I will start
with this one. Any input on efficient ways to code this would be most
appreciated.

I want to take mean (or could be other "egen"/"collapse" type summary
statistic) form all possible combinations (of subsets of various
sizes) from a set of variables.

For example, if I have v1, v2, v3, and v4, I would want the mean of
each: v1v2, v1v3, v1v4, v1v2v3, v1v2v4, v1v3v4...v3v2...v3v2v4, etc.

By v1v2v3, I mean gen v1v2v3=(v1+v2+v3)/3; (assuming the summary
statistic of interest is the mean)
by v1v2v3v4, I mean v1v2v3v4=,I mean gen v1v2v3v4=(v1+v2+v3+v4)/4.

etc.

I don't need to actually create permanent variables, simply
1. create a temporary "combination variable" (e.g., v1v2v4 =
rowmean(v1 v2 v4)) for each possible combination,
```
2. collect summary statistics of interest from "combination variables."
```3. spit out a file that conveys this information intelligibly

For example, I may want to write out a file that gives (a) the name of
the combination (e.g., v1v2v4--the column representing the rowmean of
those three variables) and (b) the mean and standard deviation of that
v1v2v4 variable.

In my particular case, I have about a 70 variable space from which to
create all these subset combinations.

Thanks,
Rob Hartman
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```
```*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```