Announcement

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

  • Keep local varlist available to use when running sections of do file

    Hi all,
    Is there a way in which I can keep a local available permanently so that I can hold a varlist in it and use it whenever I am running sections of a do file?

    What I would like to do is define a local that contains a group of conditioning variables:

    Code:
    local myvars "var1 var2 var3 ... var28 var29 var30"
    And then use it in a set of procedures related to a quasi-experiment (treatvar being the treatment) that I would like to run ad hoc by highlighting the section of do file I want to run, e.g.:

    Code:
    psmatch2 treatvar, mahal(`myvars') neighbor(2) pscore(ps1)
    
    ebalance treatvar `myvars', gen(ebwt) targets(2)
    
    tabstat `myvars', by(treatvar) stat(sum n var mean) longstub save


    I would prefer to have the local definition once at the top of my do file, run it once, and `myvars' be available whenever I then run a model. Is this possible?

    Regards,
    Will

  • #2
    Short answer is no. If your do file really is a series of distinct sections think of a master do file that is, say

    Code:
    do readin 
    do analyse 
    do collate
    calling up separate do files in turn. But that doesn't solve this problem.

    See also

    Code:
    help include
    Naturally some would want to underline that this is what a global does for you, but there are downsides to that too, as Clyde Schechter frequently and quite rightly reminds us.

    Comment


    • #3
      Thanks Nick, I will read up on what you suggest.
      I was thinking it might be possible to store the string in a scalar and then somehow use it, but I haven't been able to figure out how.

      Regards,
      Will

      Comment


      • #4
        Yes, I think that would work.

        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . scalar myvars = "weight price displacement"
        
        . di "`=scalar(myvars)'"
        weight price displacement

        Comment

        Working...
        X