**MYBOOLEAN**
capture program drop myboolean
program define myboolean
        // e.g. A, B, C, D to abcd ... ABCD
        version 8
        syntax varlist
	  tokenize `varlist'
        local nvars : word count `varlist'

        // i = 1, ..., 2^# variables
        qui forval i = 1/`=2 ^`: word count `varlist''' {
                // binary representation of i - 1
                inbase 2 `= `i' - 1'
                local ibin : di %0`nvars'.0f `r(base)'

                // initialise name and expression
                local name
                local exp "min("

                forval j = 1 / `nvars' {
                        local char = substr("`ibin'",`j',1)
                        if `char' {
                                local name "`name'``j''"
                                local exp  "`exp'``j'',"
                        }
                        else {
                                local lcj = lower("``j''")
                                local name "`name'`lcj'"
                                local exp  "`exp'1-``j'',"
                        }
                }

                // we have a trailing comma: as each arg is <= 1,
                // closing with a 2 is safe
                gen `name' = `exp'2)
        }
end