Announcement

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

  • Program error : invalid name (r198)

    Hi all,

    I am trying to get a program working that would allow me to not rewrite an if else statement 100x to highlight values greater than 0.

    However, I am getting the following error when I try to run my code:
    :
    100,8,2,17 invalid name
    r(198);



    The code is simply like:

    Code:
    local val = 100
    local row = 8
    local col = 2
    local num = 17
    
    
    capture program drop myhl
    program myhl, rclass
        
    args val row col num
        
        local perc = "%"
        if(`val' > 0) {
            putdocx table t`num'(`row',`col')=("`val'`perc'"), halign(right) shading(lime)
        }
        else {
            putdocx table t`num'(`row',`col')=("`val'`perc'"), halign(right)
        }    
    local ++row
    return local row `row'    
    end
    
    
    * and I am trying to call it with
    myhl(`val',`row',`col',`num')

    I'm very new to writing, or trying to write, programs in STATA... so any pointers would be most appreciated.

    Thanks!



    Last edited by L Rainen; 27 Mar 2022, 10:36.

  • #2
    Code:
     
     myhl `val' `row' `col' `num'

    Comment


    • #3
      Wonderful! Thanks loads!

      Comment

      Working...
      X