Announcement

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

  • Looping over pair

    Is it possible to loop over a pair rather than one each? For example, as a hypothetical code, I would write like this

    Code:
    foreach (X,Y) in ("His" "Mother")  ("His" "Father") ("Her" "Father")  {
    
    }
    If I do

    Code:
    foreach X in "His" "Her" {
    foreach Y in "Mother" "Father" {
    
    }
    then it will waste time on looping over "Her" "Mother", which I do not need.

  • #2
    hello, maybe you can first generate a new variable using -egen group- and then loop. Will it be possible?
    2B or not 2B, that's a question!

    Comment


    • #3
      Since I have no clue what you are really trying to do, I cannot comment on whether the approach is a good one. Anyway, here is an example that does what I believe you want to do

      Code:
      foreach x in "a b" "a c" "d c" {
          display "pair: `x'"
          tokenize `x'
          args one two
          display "one: `one'"
          display "two: `two'"
      }
      Best
      Daniel

      Comment


      • #4
        This works too:

        Code:
        foreach x in "a b" "a c" "d c" {
            display word("`x'", 1) 
            display word("`x'", 2) 
        }

        Comment

        Working...
        X