Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loops and interactions

    I am trying to generate lots of interactions, which I will then filter in order to eliminate near-empty cells. I can't use the usual factor-variable syntax with the command that I am interested in (lasso), because the result would be 16,000 interactions, many of which involve very few observations. In fact, I tried it, and the program ran for hours and then hung, first on my laptop, then on a pretty muscular server. So here is what I did and the interaction variables that got created:
    Code:
    . local qtest "question1 question2"
    
    . local chtest "dcount_da_cat dcount_dacrime_cat"
    . foreach q of local qtest {
      2.         foreach v of local chtest {
      3.                 xi i.`q'*i.`v',noomit
      4.         }
      5. }
    i.qu~n1*i.dco..   _IqueXdco_#_#       (coded as above)
    i.qu~n1*i.dco..   _IqueXdco_#_#       (coded as above)
    i.qu~n2*i.dco..   _IqueXdco_#_#       (coded as above)
    i.qu~n2*i.dco..   _IqueXdco_#_#       (coded as above)
    
    . d _I*,full
    
                  storage   display    value
    variable name   type    format     label      variable label
    -------------------------------------------------------------------------------------------------------------------------
    _Iquestion2_0   byte    %8.0g                 question2==0
    _Iquestion2_1   byte    %8.0g                 question2==1
    _Iquestion2_2   byte    %8.0g                 question2==2
    _Idcount_da_0   byte    %8.0g                 dcount_dacrime_cat==0
    _Idcount_da_1   byte    %8.0g                 dcount_dacrime_cat==1
    _Idcount_da_2   byte    %8.0g                 dcount_dacrime_cat==2
    _Idcount_da_3   byte    %8.0g                 dcount_dacrime_cat==3
    _Idcount_da_4   byte    %8.0g                 dcount_dacrime_cat==4
    _IqueXdco_0_0   byte    %8.0g                 question2==0 & dcount_dacrime_cat==0
    _IqueXdco_0_1   byte    %8.0g                 question2==0 & dcount_dacrime_cat==1
    _IqueXdco_0_2   byte    %8.0g                 question2==0 & dcount_dacrime_cat==2
    _IqueXdco_0_3   byte    %8.0g                 question2==0 & dcount_dacrime_cat==3
    _IqueXdco_0_4   byte    %8.0g                 question2==0 & dcount_dacrime_cat==4
    _IqueXdco_1_0   byte    %8.0g                 question2==1 & dcount_dacrime_cat==0
    _IqueXdco_1_1   byte    %8.0g                 question2==1 & dcount_dacrime_cat==1
    As you can see, the loops only acted on the last elements in the respective macros. What am I doing wrong?

  • #2
    Jeff: I'm not sure this is the issue, but have you tried embedding the locals in double-quotes, i.e.
    Code:
    xi i."`q'"*i."`v'",noomit
    Only a guess.

    Comment


    • #3
      Thanks for your help. I think I just figured this out. Every time you invoke xi, it first deletes all variables that start with _I. That's why it only left dummies from the last elements in both for loops. There is syntax to set your own prefix, which should solve the problem.

      Comment

      Working...
      X