Announcement

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

  • Generate a local with a prefix

    I have two locals set up to help me run regressions over a variety of sample restrictions. From these two locals, I would like to generate another local that can be used later to label column names for a matrix. A simplification of what I have is as follows:

    Code:
    local restrictions "=1 =2 =3 =4 =5 =6 =7 =8 =9 =10 =11 =12 =13 =14 =15"
    local res_direction "< >"
    foreach dir in `res_direction'{
    local colnames "`dir'`restrictions'"
    di "`colnames'"
    }
    But this only results in:
    Code:
    <=1 =2 =3 =4 =5 =6 =7 =8 =9 =10 =11 =12 =13 =14 =15
    >=1 =2 =3 =4 =5 =6 =7 =8 =9 =10 =11 =12 =13 =14 =15
    When I would like to see
    Code:
    <=1 <=2 <=3 <=4 <=5 <=6 <=7 <=8 <=9 <=10 <=11 <=12 <=13 <=14 <=15
    >=1 >=2 >=3 >=4 >=5 >=6 >=7 >=8 >=9 >=10 >=11 >=12 >=13 >=14 >=15
    I don't think I can solve this with a loop since that would overwrite the local each time. My understanding is that it is difficult to change the column name of individual columns in a matrix, so I want a local with all fifteen elements so I can rename the columns of a matrix all at once.
    I'm open to suggestions, but this is only a small part of a rather large program that I didn't create, so I don't want to deviate too far from this method for fear of causing other issues. Thank you!
    Last edited by Stephanie Stewart; 08 Nov 2022, 20:02.

  • #2
    Code:
    local restrictions "=1 =2 =3 =4 =5 =6 =7 =8 =9 =10 =11 =12 =13 =14 =15"
    local res_direction < >
    
    foreach dir of local res_direction {
        local colnames
        foreach res of local restrictions {
            local colnames `colnames' `dir'`res'
        }
        di "`colnames'"
    }
    which produces:
    Code:
    <=1 <=2 <=3 <=4 <=5 <=6 <=7 <=8 <=9 <=10 <=11 <=12 <=13 <=14 <=15
    >=1 >=2 >=3 >=4 >=5 >=6 >=7 >=8 >=9 >=10 >=11 >=12 >=13 >=14 >=15

    Comment


    • #3
      Here's another way:
      Code:
      local restrictions "=1 =2 =3 =4 =5 =6 =7 =8 =9 =10 =11 =12 =13 =14 =15"
      local res_direction < >
      foreach dir of local res_direction {
          local colnames: subinstr local restrictions "=" "`dir'=", all
          di "`colnames'"
      }
      which produces the same output as #2.

      Comment

      Working...
      X