Announcement

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

  • rename all words of local

    Dear all,

    I have trouble finding my way through all possible local manipulations to find what I need. I was wondering how I can rename all variable names stored in a local. Illustration:

    Code:
    local i one two three
    di "`i'"
    local i one_1 two_1 three_1
    di "`i'"
    How can I do this without redefining the local from scratch?

    Thank you in advance!

  • #2
    Code:
    local i one two three
    foreach l in `i'{
    local k "`k' `l'_1"
    }
    di "`k'"
    Result:

    Code:
    . local i one two three
    
    . 
    . foreach l in `i'{
      2. 
    . local k "`k' `l'_1"
      3. 
    . }
    
    . 
    . di "`k'"
     one_1 two_1 three_1

    Comment


    • #3
      thanks!

      Comment


      • #4
        Here is an alternative:

        Code:
        local i one two three
        local i : subinstr local i " " "_1 ", all
        local i = "`i'_1"
        di "`i'"
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment

        Working...
        X