Announcement

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

  • Creating a new list of variables by using all possible combinations of one variable

    Hello,

    I am looking to create a new list of variables based on all possible combinations of a single variable. I've attached photos of an example. I want all possible combinations of 3 people and the sums of their x and y values.

    The math would suggest there will be 120 possible combinations: n! / r! (n - r)! = (10!) / (3!)((10-3)!) = 120

    I've found ways to combine variables, but no such luck finding a way to get all possible combinations, much less the sums of x and y as well.

    Any help would be appreciated.

    Thanks so much!
    Last edited by Ethan Peake; 26 Oct 2015, 00:49.

  • #2
    Code:
    clear
    input str6 name x y
    "bob" 34 87
    "steve" 65 55
    "james" 88 42
    "joe" 24 13
    "bill" 14 86
    "jordan" 59 92
    "tom" 44 24
    "jerry" 37 47
    "larry" 28 68
    "mike" 69 30
    end
    
    tempfile temp
    save `temp'
    rename name name2
    rename x x2
    rename y y2
    cross using `temp'
    
    gen xsum = x + x2
    gen ysum = y + y2
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment

    Working...
    X