Announcement

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

  • random selection of variables in a list


    Hi

    I have constructed an indicator using a set of variables, and I'm interested in assessing the robustness of this indicator to the choice of variables included. One approach I'm considering is to randomly select a subset of variables from the original list and construct the indicator multiple times with different variable combinations.

    For example, let's say I have the following list of variables:

    Code:
    local variable_list "hsup maison a2c cvfvp joindre"
    Now, I want to randomly select 3 variables from this list to create a new list, and repeat this process multiple times to obtain several lists of variables, each with a different combination. Let's call these lists varlist1, varlist2, varlist3, etc. i thought about extracting words from the local but i do not know how to do that randomly and without replacement.

    Could you please provide guidance on how to implement this in Stata? Specifically, how can I randomly select a subset of variables from the original list and repeat this process to create multiple variable combinations?

    Thank you in advance for your help and suggestions.

  • #2
    One approach is to use the user-written command -tuples- to create macros containing all possible combinations of the desired size; see -ssc describe tuples-.
    Code:
    local nchoose = 2
    local variable_list "hsup maison a2c cvfvp joindre"
    mac drop _tuples*
    tuples `variable_list', min(`nchoose') max(`nchoose')
    forval i = 1/`ntuples' {
       di "List `i': `tuple`i''"
    }
    If there are too many possible sub-variable lists to use, you could sample from among them by randomly shuffling the variable list in advance, and using just the first (say) 10 of the lists produced by -tuples-, that is, tuple1 through tuple10. At the moment, I can't quickly think of a short snippet of Stata code to shuffle the items in the variable list programmatically, but it can be done. The Mata function -jumble()- could be useful for this.

    Comment

    Working...
    X