Hi Jack,

thanks for your help!

I'm was experimenting with loop commands for each element of the 'dataset matrix' but the code soon got too 'long'.
The unpacking of the list in conjunction with the dummify command is super - hansl impresses me more and more.

Have a nice day
Leon

Am 28.05.2012 17:35, schrieb Riccardo (Jack) Lucchetti:
On Mon, 28 May 2012, Paolo Caliò wrote:

Hello!

I need to create some dummy variables in order to capture all the possible
combinations of a certain set of variables.
[...]

Does this help?

<hansl>
function list CombinDums(list X)
    scalar pwr = 1
    series category = 0
    loop foreach i X --quiet
        category += pwr * (X.$i>0)
        pwr *= 2
    end loop

    list ret = dummify(category)
    return ret
end function

nulldata 32
set seed 1234

series a = normal()
series b = normal()
series c = normal()

list X = a b c
list D = CombinDums(X)
</hansl>

--------------------------------------------------
 Riccardo (Jack) Lucchetti
 Dipartimento di Economia

 Università Politecnica delle Marche
 (formerly known as Università di Ancona)

 r.lucchetti@univpm.it
 http://www2.econ.univpm.it/servizi/hpp/lucchetti
--------------------------------------------------


_______________________________________________
Gretl-users mailing list
Gretl-users@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users