[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

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

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: SAS like command? |

Date |
Thu, 18 Aug 2005 14:03:55 +0100 |

A comment on

bysort a b c: egen tabulation = sum(1)

I have used -egen, sum(1)- myself in examples, but it also

involves Stata interpreting about 100 lines, when one

will do the same job:

bysort a b c : gen tabcount = _N

On the original problem, I would suggest

egen group = group(a b c), label

tabstat n, by(group) stat(N sum)

for interactive use. For a program, given that

properly labelled output is essential for

the problem, I would probably use the same -egen-

call, a few -generate-s and a -tabdisp- for the display.

Nick

n.j.cox@durham.ac.uk

>>> James Muller

Here's a rough procedure:

Start with your dataset. Choose the variables you want to keep, suppose these are variables a, b and c

. bysort a b c: egen tabulation = sum(1)

. duplicates drop

Then you should have the below table as your new dataset.

Here's a simple example program that will simply output the data. If you're going to use this frequently, save it as tabNway.ado and put it in your adopath.

program define tabNway

preserve

keep `*'

sort`*'

by `*': egen tabcount = sum(1)

duplicates drop

list

restore

end

In your case you would use input 'tabNway a b c'. I didn't use a tempvar because that gives a meaningless heading in the list. To get your other heading you can edit the program.

*

* For searches and help try:

* http://www.stata.com/support/faqs/res/findit.html

* http://www.stata.com/support/statalist/faq

* http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**Re: st: Mata vs C** - Next by Date:
**st: Re: egen mean function** - Previous by thread:
**RE: st: RE: SAS like command?** - Next by thread:
**st: egen mean function** - Index(es):

© Copyright 1996–2017 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |