Announcement

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

  • going through every possible combination of variables in a loop

    Hi ,

    I have 4 core variables which I always need to include and 80 potential variables.
    I want to check if there are more than 200 ids remaining if I am doing the loop with all the 10 variables
    I am using the following loop to clean the data up like I want it:

    foreach x in 1 2 3 4 5 6 7 8 9 10 {
    drop if missing(`x')
    }

    Lets say 1-4 are core variables and 5-10 are potential variables (out of 80 possible)
    How can I extend this loop to go though potential combinations of 1 2 3 4 x x x x x x (x representing a potential variable of the 80)
    I hope sombody can help me with this issue

    Best,
    JB

  • #2
    This is not possible. There are approximately 1.2 * 1024 possible combinations with 80 variables. There is no way that this will run in your lifetime. Probably not even in the lifetime of the solar system.

    Moreover, it's unclear what the point of this would be. After you have run the loop you show*, you will have already dropped any observation with a missing variable from the list. Looking for combinations of variables will not turn up anything additional to drop. If a combination of variables were missing, you would have already dropped it.

    *The loop you show, of course, will not actually run because x needs to be a variable name, and numbers like 1 through 10 are not legal variable names.

    Finally, there is an easier way to drop observations that are missing any of your 80 potential variables. Start by creating a list of those names. (If they are systematically named, using -unab-, or -ds- and capturing `r(varlist)' in a local macro will do it. If the names are arbitrary and unrelated, you'll just have to write them out once.) Anyway, let's assume the list of variables is in the local macro vbles. Then:

    Code:
    mark keeper
    markout keeper `vbles', strok
    drop if !keeper
    drop keeper
    Added: If you only want a count of the observations with no missing values, instead of -drop if !keeper-, use -count if keeper-.

    Correction: Given that you are only interested in combinations that include 1, 2, 3, and 4 (or rather the actual names of the 4 key variables) the number of combinations is a tad smaller: 7.6*1022. This is still not even remotely feasible.
    Last edited by Clyde Schechter; 24 Mar 2022, 10:08.

    Comment


    • #3
      Okay Tanks a lot for the explanation!

      Comment


      • #4
        HaHa! There is a computation simplication method for accomplishing more or less what you want within the life of the solar system. Use stepwise selection, function stepwise.

        Comment

        Working...
        X