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.

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

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: collapsing rows and generating new smaller dataset |

Date |
Fri, 8 Jun 2012 11:12:01 +0100 |

Assuming that age groups 40-44 ... 75-79 are 1 ... 8 underneath, then you need a new grouping variable that is gen new_age_group = cond(age_grp <= 2, 1, cond(age_grp <= 6, 2, 3)) or you can do something similar with -recode-. The assumption won't be correct, but the principle will be the same. That is, -collapse- needs to be fed a grouping variable created in advance; I don't think there is an easier way to do it. But the difficult ways to do it are all one line long. Nick n.j.cox@durham.ac.uk Tim Evans I have a dataset in Stata 11.2 that contains the following: age_grp f_pop m_pop tot_pop 40-44 7000 7000 14000 45-49 7000 7000 14000 50-54 7000 7000 14000 55-59 6000 6000 12000 60-64 5000 5000 10000 65-69 4000 4000 8000 70-74 3000 3000 6000 75-79 2000 2000 4000 What I want to do is collapse this down so that I have the following three categories which have the sum of each level of age-grp: age_grp2 f_pop m_pop tot_pop 40-49 50-69 70-79 What I would like to know is how I can collapse the above, but sum the populations of each variable. I.e 40-49 for f_pop will be the sum of 40-44 and 45-49 and so on. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**Re: st: imputing dates into a string date***From:*daniel klein <klein.daniel.81@googlemail.com>

**st: collapsing rows and generating new smaller dataset***From:*Tim Evans <Tim.Evans@wmciu.nhs.uk>

- Prev by Date:
**st: RE: collapsing rows and generating new smaller dataset** - Next by Date:
**st: RE: -encode- with predetermined sorting** - Previous by thread:
**st: collapsing rows and generating new smaller dataset** - Next by thread:
**st: RE: collapsing rows and generating new smaller dataset** - Index(es):