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

From |
James Muller <james.muller@internode.on.net> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: SAS like command? |

Date |
Thu, 18 Aug 2005 10:51:49 +1000 |

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.

Cheers

James

Ricardo Ovaldia wrote:

Dear all,

SAS's proc mean with the class command expands the

class variables creating all possible combinations

including data with missing data. Is there a way to

do this in Stata?

Thank you,

Ricardo.

Example:

Starting with these data:

Obs a b c n

1 0 0 0 3

2 0 0 1 4

3 0 1 1 5

4 1 1 1 10

5 0 1 0 7

6 0 1 1 5

7 1 0 0 8

8 1 0 1 9

The SAS command:

proc means;

class a b c;

var n;

output sum=tsum ;

Yields:

Obs a b c _TYPE_ _FREQ_ tsum

1 . . . 0 8 51

2 . . 0 1 3 18

3 . . 1 1 5 33

4 . 0 . 2 4 24

5 . 1 . 2 4 27

6 . 0 0 3 2 11

7 . 0 1 3 2 13

8 . 1 0 3 1 7

9 . 1 1 3 3 20

10 0 . . 4 5 24

11 1 . . 4 3 27

12 0 . 0 5 2 10

13 0 . 1 5 3 14

14 1 . 0 5 1 8

15 1 . 1 5 2 19

16 0 0 . 6 2 7

17 0 1 . 6 3 17

18 1 0 . 6 2 17

19 1 1 . 6 1 10

20 0 0 0 7 1 3

21 0 0 1 7 1 4

22 0 1 0 7 1 7

23 0 1 1 7 2 10

24 1 0 0 7 1 8

25 1 0 1 7 1 9

26 1 1 1 7 1 10

Ricardo Ovaldia, MS

Statistician Oklahoma City, OK

____________________________________________________

Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs

*

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

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

**References**:**st: SAS like command?***From:*Ricardo Ovaldia <ovaldia@yahoo.com>

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

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