Announcement

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

  • lasso error message

    hello, i have tried to test the lasso command using a dataset where i try to predict a continuous dependent variable using sets of categorical and continuous independent variables.
    i have followed chuck hubers lasso tutorial steps and here is my command: lasso linear continuousdepvar $ifactors $vlcontinuous
    but for some reason i get the error message: "depvar can not be specified in (alwaysvars) othervars"
    could anyone tell me what i am doing wrong?
    thanks
    Mathieu

  • #2
    "alwaysvars" and "othervars" each refer to predictors and thus the dependent variable (called "depvar" in the Stata message) should not be included; since you don't show us the definitions of the globals (please read the FAQ and follow it's advice), more specific information cannot be given

    Comment


    • #3
      To Rich's advice I will add that you should tell us where to find "chuck hubers lasso tutorial steps" that you are trying to follow.

      Comment


      • #4
        hello, here is the link to the stata tutorial for lasso by chuck huber on stata 16, which i also use. i actually tried with the fake survey dataset he uses in the tutorial, i replicated the same commands he typed and i still get the same error message "depvar can not be specified in (alwaysvars) othervars"
        https://www.youtube.com/watch?v=efYBzFcKWn8

        Comment


        • #5
          Here's the problem with the tutorial code copied from the tutorial video that you linked to.

          When we webuse the example data
          Code:
          . webuse fakesurvey, clear
          (Fictitious survey data)
          
          . vl set, categorical(4) uncertain(0)
          
          -------------------------------------------------------------------------------
                            |                      Macro's contents
                            |------------------------------------------------------------
          Macro             |  # Vars   Description
          ------------------+------------------------------------------------------------
          System            |
            $vlcategorical  |     115   categorical variables
            $vlcontinuous   |      47   continuous variables
            $vluncertain    |       0   perhaps continuous, perhaps categorical variables
            $vlother        |       9   all missing or constant variables
          -------------------------------------------------------------------------------
          we create the variable lists shown. However $vlcontinuous includes the variable q104 which will be used as the dependent variable in the lasso command, and we get the error message you saw.
          Code:
          . lasso linear q104 ($idemographics) $ifactors $vlcontinuous if sample==1, rseed(1234)
          depvar may not be specified in (alwaysvars) othervars
          r(198);
          (And as an aside, we note that $idemographics was not defined in the video, but this is not in and of itself a problem, although it may be why my results do not match those in the video.)

          The solution to the problem is to add after the vl set command
          Code:
          . vl drop (q104), system
          note: 1 variable specified; 1 variable removed from vl system macros.
          to drop the q104 variable from $vlcontinuous. Then the error message is eliminated and lasso runs successfully.

          So you will need to add
          Code:
          vl drop (continuousdepvar), system
          to your code for your model.

          Comment


          • #6
            wonderful, thanks a lot!

            Comment


            • #7
              sorry but i get this: vl drop(depvar), system
              "drop(depvar) invalid vl subcommand"

              Comment


              • #8
                You have not proofread what you typed and compared it to the code presented in post #5; had you done so you would have seen that you omitted the space following the drop subcommand and and preceding the left parenthesis surrounding the variable list..
                Code:
                help vl
                Last edited by William Lisowski; 28 May 2022, 15:51.

                Comment


                • #9
                  ok it works
                  thanks a lot

                  Comment

                  Working...
                  X