On Sat, 10 Nov 2012, Pindar wrote:
I'd be thankful for 'a cheat' in order to improve my code
on interaction
between the factor steps.
I hereby also want to make the proposal of adding a new function to GRETL
called 'interaction'
that could be used like 'dummify'. I'm thinking of something like
interaction(series or list [discrete variables], optional series or list).
If only one argument is given this would be the case of the example below, if
two arguments are given the case of the user guide is tackled.
Up until now I generated interaction series according to the example on p.121
in the guide.
Now with factor step combinations it's getting really tricky:
1) make the list of factors -> ok
2) make dummies for all steps of each factor -> ok
3) interact the dummies BUT without replications -> here I have a
problem
What if there are more than two factors? My 'if condition' is not that good.
I'm using the 'loop foreach' construction.
<hansl>
dummify factors
loop foreach i factors-q
sprintf ni "%d",i
list Dum_$i=null
string str="D$i*"
list Dum_$i=@str
endloop
[...]
Im not sure I exactly understand what you're aiming for, but if I'm
guessing right you want something like this (assuming two factor
series named F1 and F2):
<hansl>
# create lists of dummies for F1, F2 values
list DF1 = dummify(F1, NA)
list DF2 = dummify(F2, NA)
list Interact = null
string vname
# create list of cross-products
loop foreach i DF1 -q
loop foreach j DF2 -q
vname = "$i_$j"
series @vname = $i * $j
Interact += @vname
endloop
endloop
</hansl>
Now Interact will hold a list of terms such as DF1_1_DF2_1,
DF1_1_DF2_2,...,DF1_3_DF2_4.
This should generalize to more than two series without too much
trouble, though generalizing it to an arbitary number of series, not
known in advance, would not be trivial.
Allin Cottrell