Announcement

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

  • Create varlist with categorial interactions for lasso

    Hi I am preparing my data for carrying out Lasso and I dont understand how I can create interactions between my categorial variables in the categorial list I created?
    I first create a list with my 2 continous variables
    vl create cont = (age ln_cit_tot)
    Then a list with my 64 categorial variables incl. dummies
    vl create cat = (x1, x2, x3....x64)
    Then I do my entire list
    vl substitute myvarlist = i.fact cont i.fact#c.cont
    However this does not include the interactions between all variables in cat (x1#x2 x1#x3 x2#x3.....)

    How can I make sure that I also include the interactions between the categorials in my variable list?
    Thanks
    Last edited by Pauline Mattsson; 03 Feb 2023, 08:02.

  • #2
    I think you will need tuples from SSC to create such combinations. I do not know any operation that will do that automatically.

    Code:
    *ssc install tuples, replace
    macro drop _all
    *ASSUME VARNAMES ARE x1-x5
    tuples x1 x2 x3 x4 x5, max(2) min(2)
    *GENERATE COMBINATIONS
    forval i= 1/`ntuples'{
        local list "`list' `=subinstr("`tuple`i''", " ", "#", .)'"
    }
    Res.:

    Code:
    . di "`list'"
     x4#x5 x3#x5 x3#x4 x2#x5 x2#x4 x2#x3 x1#x5 x1#x4 x1#x3 x1#x2

    Comment


    • #3
      Thanks a lot this worked. One more question if I now want to add this interaction list (called allint) with my categorical list (called cat) and continuous list (called cont) and create a new list called factors how do I proceed?
      vl create factors = cat + cont + ??

      Comment


      • #4
        Code:
        local wanted= "$cat"+ " "+ "$cont"+ " " + "`allint'"
        display "`wanted'"

        Comment


        • #5
          Hi again so when I run the regression with the allint I still dont get all the interactions. For example:
          logit sback_no $cont $cat "`allint'"
          I only get that (all interactions listed i.e env_persist#grp_at) not allowed
          I will run it with a dslogit but just trying the normal logit

          Sorry for me not understanding..
          Last edited by Pauline Mattsson; 08 Feb 2023, 02:40.

          Comment


          • #6
            You need double quotes for displaying the contents of a local or global. Within an estimation command e.g., logit, you omit them as you have done for your globals.

            Code:
            logit sback_no $cont $cat `allint'

            Comment

            Working...
            X