Announcement

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

  • referring to multiple variables in st_store

    hello

    In the following st_store, wondering if there is a better way to refer to the variables (such as through varlist a*) , instead of listing each one individually in a cumbersome way..

    Code:
    clear
    set obs 10
    mata
    var = ("a1", "b2",  "a3", "b4",  "a5")
    st_addvar(("float"), var)
    st_store(.,("a1", "a3", "a5"),J(10,3,1))  //
    
    end

    Thanks!
    Last edited by charlie wong; 25 Dec 2017, 01:42.

  • #2
    I have only version 12, so I don't know whether Stata corp. has changed the behavior of st_store() since to allow the use of wildcards or abbreviations of variable list. I guess it isn't the case.
    It is unlike st_data() which allows it.
    It is possible to work around this problem by creating a function which uses the Stata unab command and returns the unabbreviated list in a rowvector of strings. The function doesn't handle the case where the variable list doesn't exist.


    Code:
    clear
    set obs 10
    clear mata
    mata:
    string rowvector unab(string abvlist)
    {
            stata("unab vlist: "+ abvlist)
            return(tokens(st_local("vlist")))
    }
    end
    
    mata
    var = ("a1", "b2",  "a3", "b4",  "a5")
    st_addvar(("float"), var)
    // st_store(.,("a1","a3","a5"),J(10,3,1))  //
    st_store(.,unab("a*"),J(10,3,1))  
    end

    Comment


    • #3
      Thanks a lot for the reply, Christophe!

      Comment

      Working...
      X