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

st: loop problem?


From   "Jun Xu" <mystata@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: loop problem?
Date   Sun, 09 Feb 2003 09:13:15 -0600

I think I might not have explained my problems clearly. I have k indicator variables (coded as 1 or 0) and I would like to know the response patterns (for example for latent class analsis) to these k variables. For example,

var1 var2 var3 ....vark
1 0 0 0
0 1 0 0
...
1 1 0 0
...
...
...
1 1 1 1

I would like to know for each response pattern, how many cases are there, and programmed into an ado file. My key problem here is how to run through all the combinations (univariate, bivariate, and trivariate)

One posibility is that I used the following cods (or reviced version to fit into an ado file)

******************************************************************
clear
for num 1/6: set obs 100\ gen xX=invnorm(uniform()) \ gen DxX=xX>0.6
gen pattern=0
local i=1
while `i'<6 {
replace pattern=pattern+Dx`i'*10^(6-`i')
local i=`i'+1
}

aorder
list Dx1-Dx6 pattern
sort pattern
list pattern
gen count=1
collapse (sum) count, by(pattern)
***********************************************************
The resulting data matrix looks like:

============================
pattern count
0 16
10 10
100 5
110 6
1000 8
1010 7
1100 2
1110 1
10000 11
10010 3
10100 2
10110 2
11000 2
11010 2
11100 1
100000 7
100010 1
100100 2
101000 4
101010 1
110000 1
110010 2
110100 2
111000 1
111010 1
=================================


Here the problem is that it only presents the response pattern that has at least one case and it's hard to handle its order (now is list in numerical order: from small to big)
But what if I want to go through "each" combination (2^k possible ways) in a sysmatic way and list all response pattern freqeuncy though some of them have zero cases. What I meant by a systematic way is like:

*********************************************************************
var1
var2
var3
...
...
...
vark
var1 var2
var1 var3
var1 var4
...
...
var1 vark
var2 var3
var2 var4
...
...
var(k-1) vark
...
...
var1 var2 var3
var1 var2 var4
var1 var2 var5
...
var1 var2 var3....vark
******************************************************************

or in binary coding
****************************************************************
1 0 0 0 0 .....0
0 1 0 0 0 .....0
0 0 1 0 0 .....0
...
...
...
0 0 0 0 0 .....1
1 1 0 0 0 .....0
1 0 1 0 0 .....0
1 0 0 1 0 .....0
...
...
1 1 1 0 0 .....0
1 0 1 1 0 .....0
...
...
...
...
1 1 1 1 1 .....1
***********************************************

Here I didn't present some summarize command that could grab case number for that response pattern. But basically I will run through each combination and calculate the frequency for that particular combination though there might be zero cases. Thanks a lot


Jun Xu
Department of Sociology
Indiana University at Bloomington





_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail

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