Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Aggregate different parts of data selectively


From   Chris Yang <[email protected]>
To   [email protected]
Subject   st: Aggregate different parts of data selectively
Date   Mon, 3 Feb 2014 14:24:38 -0500

Dear All,

I have a dataset of the following structure:

group no var1 var2 var3
1       1   3     2      1
1       2   2     0      0
1       3   3     0      1
1       4   0     1      1
1       5   1     1      2
...
2       1   3     2      1
2       2   3     0      0
2       3   1     1      1
2       4   0     2      1
2       5   0     0      2
...
3       1   1     1      1
3       2   2     3      1
3       3   2     1      1
...

I want to aggregate a subset of observations by group, e.g. aggregate
(using the mean) all the observations with `no` > 2 in group 1,
aggregate observations with `no` > 5 in group 2, aggregate
observations with `no` > 3 in group 3, and so on. And carry out
analysis using the aggregated data of different groups only.

I know that --collapse-- can do the averaging job within each group,
however, it will also replace all existing data with the aggregated
data. In my case, it would mean that I lose the data for all the other
groups once I collapse/aggregate for any single group.

A tedious way is to collapse and save respective groups individually,
and then merge the aggregated per-group data in the end. I wonder if
there is a more efficient way to achieve my goal here?

Your thoughts and suggestions are appreciated. Thanks.

Best regards,

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index