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

# st: RE: collapsing rows and generating new smaller dataset

 From Tim Evans To "'statalist@hsphsun2.harvard.edu'" Subject st: RE: collapsing rows and generating new smaller dataset Date Fri, 8 Jun 2012 11:07:52 +0100

```Hi all,

Apologies, I think I have it now:

gen age = 1 if inlist(age_grp,"40-44", "45-49")
replace age = 2 if inlist(age_g, "50-54", "55-59", "60-64", "65-69")
replace age = 3 if inlist(age_g,"70-74", "75-79")

collapse (sum) f_pop m_pop tot_pop, by(age)

age	f_pop	m_pop	tot_pop
1	14000	14000	28000
2	22000	22000	44000
3	5000	5000	10000

Best wishes

Tim

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Tim Evans
Sent: 08 June 2012 10:47
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: collapsing rows and generating new smaller dataset

Hi all,

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.

Any ideas appreciated

Tim
_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.

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

_DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.

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