Announcement

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

  • Storing specific local names in a local

    Hello everyone,

    This example does not have a dataset with it as I am just looking for a way to call locals with a particular name within a two-way plot

    For example:

    Code:
        local c = 1
        
        levelsof month1, local(lvls)
        
        foreach x of local lvls {
        foreach var of varlist eng11 eng22 eng33 eng44 {
        
            colorpalette tableau, n(4) nograph
            
                if `c' > 4 {
                    local c = 1
                }
            
                local start = 2.5
                local end : display `=_N' - 1
                
                forvalues i = 1/`end' {
            
                    local j = `i' + 1
                    local nextbar = `start' + 1
                
                    local lines`i' `lines`i'' (scatteri `=`var'[`i']' `start' `=`var'[`j']' `nextbar', recast(line) lpattern(dash) lcolor("`r(p`c')'") lwidth(0.15)) ||
                    
                    local start = `start' + 2
                
                }
            
            local ++c
            
            }
        
        }
    The following generates 2 locals by the name of `lines1' and `lines2'. As time goes by, this may even be lines 1 to 3 and so on.

    I want to list these locals within the twoway command as below automatically:

    Code:
    #delimit ;
    twoway
    `bars' `lines1' `lines2' `scatter'
    ,
    scheme(white_tableau)
    legend(order(1 2 3 4) label(1 "Inactive") label(2 "Low") label(3 "Medium") label(4 "High") pos(4) size(2))
    yscale(range(0 `maxuser') noline)
    ylabel(`ylab0', nogrid labsize(2.25) noticks)
    xlabel(2 "April" 4 "May" 6 "June", nogrid)
    xtitle("")
    ;
    #delimit cr
    It would be nice to somehow list line1 and line2 and so on by not manually typing them, such as:

    Code:
        #delimit ;
        twoway
        `bars' `all_lines' `scatter'
        ,
        scheme(white_tableau)
        legend(order(1 2 3 4) label(1 "Inactive") label(2 "Low") label(3 "Medium") label(4 "High") pos(4) size(2))
        yscale(range(0 `maxuser') noline)
        ylabel(`ylab0', nogrid labsize(2.25) noticks)
        xlabel(2 "April" 4 "May" 6 "June", nogrid)
        xtitle("")
        ;
        #delimit cr
    Please feel free to let me know if there is difficulty understanding my question; I will try my best to explain again.

  • #2
    Here is some technique which may start you in a useful direction.
    Code:
    . local a aaa
    
    . local b bbb
    
    . local c ccc
    
    . local Z \`a' \`b' \`c'
    
    . macro list _Z
    _Z:             `a' `b' `c'
    
    . local Y `Z'
    
    . macro list _Y
    _Y:             aaa bbb ccc
    
    .

    Comment


    • #3
      Thank you this is a good starting point now just need to see how to make it happen automatically!

      Comment

      Working...
      X