Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: SAS like command?


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: SAS like command?
Date   Thu, 18 Aug 2005 06:25:20 -0500

Ricardo,

Here is one way:
...
postclose `hold'
preserve
use `results', clear

*create _TYPE_ variable
local i = 0
gen type = 0
foreach a in == != {
foreach b in == != {
foreach c in == != {
	replace type = type + `i'  if a `a' . & b `b' . & c `c' .
	local ++i
}
}
}

li
restore
drop if a == .


Scott

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of Ricardo Ovaldia
> Sent: Wednesday, August 17, 2005 8:57 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: RE: SAS like command?
> 
> 
> Thank you Scott. That work great. Is there an easy way
> to also get the _TYPE_ variable or do I need to hard
> code it?
> 
> regards,
> Ricardo.
> 
> 
> --- Scott Merryman <smerryman@kc.rr.com> wrote:
> 
> > Ricardo,
> >
> > Here is oneway.  Note, it does give 27 combination,
> > the combination that SAS
> > does not report is (a = 1, b = 1, c = 0 ==> sum =
> > 0).  I suppose you could
> > add a statement to drop if sum == 0.
> >
> > count
> > set obs `=r(N) + 1'
> >
> > tempfile results
> > tempname hold
> >
> > postfile `hold' a b c  freq sums using `results'
> > qui {
> > levelsof a,  missing local(a)
> > levelsof b, missing local(b)
> > levelsof c, missing local(c)
> >
> > foreach j of local a  {
> > foreach k of local b  {
> > foreach l of local c  {
> > 	sum n if a != `j' & b !=`k' & c != `l'
> > 	local sums = r(sum)
> > 	local freq = r(N)
> > 	local j = abs(`j' - 1)
> > 	local k = abs(`k' - 1)
> > 	local l = abs(`l' - 1)
> > 	post `hold' (`j') (`k') (`l') (`freq') (`sums')
> > }
> > }
> > }
> > }
> > postclose `hold'
> > preserve
> > use `results', clear
> > li
> > restore
> > drop if a == .
> >
> >
> > Hope this helps,
> > Scott
> >
> >
> > > -----Original Message-----
> > > From: owner-statalist@hsphsun2.harvard.edu
> > [mailto:owner-
> > > statalist@hsphsun2.harvard.edu] On Behalf Of
> > Ricardo Ovaldia
> > > Sent: Wednesday, August 17, 2005 7:04 PM
> > > To: statalist@hsphsun2.harvard.edu
> > > Subject: st: SAS like command?
> > >
> > > 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/
> >
> 
> 
> Ricardo Ovaldia, MS
> Statistician
> Oklahoma City, OK
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> *
> *   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/



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