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

st: RE: SAS like command?


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: SAS like command?
Date   Wed, 17 Aug 2005 20:35:39 -0500

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: [email protected] [mailto:owner-
> [email protected]] On Behalf Of Ricardo Ovaldia
> Sent: Wednesday, August 17, 2005 7:04 PM
> To: [email protected]
> 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/



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