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

st: RE: loop (please ignore previous)


From   "Jun Xu" <mystata@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: RE: loop (please ignore previous)
Date   Sun, 16 Feb 2003 00:42:30 -0600

Stata-listers/Nick,

Thanks a lot for your help, and I have managed to write an ado file that seems to work fine till I found out that it won't work with a varlist of more than 8. I have attached our previous Q&A emails.

Several Notes:

`imax': a macro that I have grabbed using 2^`nvars'-1, where `nvars' is a macor containing number of variables in the varlist.

part of the ado file that's relevant to my question
************************************************************************
......
......
......
quietly gen `pat02'=.
format `pat02' %0`nvars'.0f

*create other tempvars

forval i = 1 / `imax' {
qui inbase 2 `i'


local which : di %0`nvars'.0f `r(base)'

*local a="`which'"
*di "`which'"

forval j = 1 / `nvars' {
local char = substr("`which'",`j',1)

*I only invoke `which' once within this loop
.......
.......
.......

}


quietly replace `pat02'=`which' if _n==`i'


*di _n(1) "`which'"
*di `pat02'[`i']
*di %0`nvars'.0f `which'

quietly replace `pat10' =`i' if _n==`i'

*replacing values of other tempvar

......
......
......

}
......
......
......
************************************************************************

Here one function of this ado file is to go through all combinations of variables in the varlist and to calculate the listwise nonmissing sample size. For example if the syntax is:

permlist var1 var2 var3 var4 var5 var6, patmis(001001)

It will produce the listwise nonmissing sample size for var3 var6 (so a "0" within patmis options indicates exclusion from the listwise nonmissing sample size calculation, and a "1" indicates inclusion.
And it will also calculate all listwise nonmissing sample size for any combinations (choose 1 to 6 out of 6 = 2^6 combinations, except the possibility of choosing none) of variables among these six variables (var1-var6). Results as follow, and the only difference is that I used 9 variables. I only grab the portion that starts to pose problems:

***************************************************
......
......
......
011101110 | 1387
011101111 | 1387
011110000 | 1192
011110001 | 1192
011110010 | 1192
011110011 | 1192
011110100 | 1192
011110101 | 1192
011110110 | 1192
011110111 | 1192
011111000 | 1191
011111001 | 1191
011111010 | 1191
011111011 | 1191
011111100 | 1191
011111101 | 1191
011111110 | 1191
011111111 | 1191
100000000 | 1388
100000008 | 1388
100000096 | 1388
100000104 | 1388
100000112 | 1388
100001000 | 1387
100001008 | 1387
100001104 | 1387
100001112 | 1387
100010000 | 1192
100010008 | 1192
100010096 | 1192
100010104 | 1192
100010112 | 1192
100011000 | 1191
100011008 | 1191
......
......
......
***************************************************
What I did in my ado program is to tabdisp "pat02" (binary codes used for indicating inclusion or exclusion from my listwise nonmissing sample size calculation) with "nomiscnt" (nonmissing case counts).



_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 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