Announcement

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

  • global xlist and ylist

    Dear All,
    I am running biprobit command in stata. Since I have so many explanatory variables and also having to run many models using same explanatory variables, I define my dependent and independent variables as follow:
    macro define w x1 x2 x3 etc.
    macro define z z1 x1 x2 x3 etc.
    Then i ran following command:
    biprobit (y1=$w1) (y2=$z)
    BUT i get following error:
    "invalid something: unmatched close parenthesis or bracket"

    I defined using "global" command as follow:
    glolbal w x1 x2 x3 etc.
    global z z1 x1 x2 x3 etc.
    global d1 y1
    global d2 y2
    Then I ran following command:
    biprobit ($d1=$w1) ($d2=$z1) ; However I am getting same error message as follow:
    "invalid something: unmatched close parenthesis or bracket"

    I search for similar discussion in statalist but I failed to useful information. I would grateful for the help. Many thanks in advance.

    Also I am using stata 13.

  • #2
    When you write -biprobit (y1 = $w1) (y2 = $z)-, you are referencing a global macro w1 that does not exist. You defined a macro w, but not a w1. Similarly, in -biprobit ($d1 = $w1) ($d2 = $z1)-, both global macros w1 and z1 are non-existent. The error message you are getting is not particularly informative: the problem isn't really about unmatched parentheses or brackets, it's about undefined macros.

    As an aside, in your second try, your first command begins with -glolbal-, which is a non-existent command. I assume this is a typographical error you made in posting, because if you actually ran that command you would have gotten an error message right there. But one thing you shouldn't do here is type your code directly into the forum. Little details that the human eye misses are often crucial. You should always show the exact code you actually ran, by copy/pasting from your do-file or the Results window into the Forum editor. (And put it between code delimiters -- see FAQ #12 for instructions -- so it always comes out easily readable.)

    So that's easy for you to fix. But let me add that the use of global macros for this purpose is unwise. Global macros are subject to name clashes with global macros defined in other programs that are running. This is a real problem because you can't always know what other programs are running when you run your code. The bugs that are caused when such name-clashes arise are extremely frustrating to find and fix. So it is much safer to use local macros, which never clash with anything outside their own do-file (or command-line window session). Thus, a fix to your problem is:

    Code:
    local w x1 x2 x3
    local z z1 x1 x2 x3
    local d1 y1
    local d2 y2
    biprobit (`d1'= `w') (`d2' = `z')
    Note: I'm assuming you want the -biprobit- to expand to -biprobit (y1 = x1 x2 x3) (y2 = z1 x11 x2 x3)-.
    Last edited by Clyde Schechter; 11 Jan 2017, 22:06.

    Comment


    • #3
      As always your advices are always very helpful for me. Many thanks for this time. Following your suggestion I did following and I am still getting same error message. My commands are as below:
      Code:
      *Define xlist
      local x1 tel ele rad age edu fem hhs chi loa urb expe mar roa for
      
      local x2 ope ele tel ele rad age edu fem hhs chi loa urb expe mar roa for
      
      local y1 cf1
      local y2 tel
      
      *Choice Model
      biprobit (`y1' = `x1') (`y2' = `x2')
          est store fullsample
      Thank you again.

      Comment


      • #4
        The local definitions have to be visible to each other. One way that would not be true is if you are issuing these definitions one by one from a do-file editor window. To see which definitions are "known", type

        Code:
        macro list 
        in the same place as you are executing the definitions.. By the way, the purpose of the first definitions may be to save typing and produce concise statements, but there is no such reason for the second pair. This would be fine.

        Code:
        local x1 tel ele rad age edu fem hhs chi loa urb expe mar roa for
        local x2 ope ele tel ele rad age edu fem hhs chi loa urb expe mar roa for
        biprobit (cf1 = `x1') (te1 = `x2')

        Comment


        • #5
          Thank you Nick. This works for me perfectly.

          Comment


          • #6
            Hi, I am trying to run a single regression for 2500 different dependent variables with the same explanatory variables. My current code is:

            global xlist var1 var2 var3
            foreach y in $xlist {
            2.. reg `y' x1 x2 x3
            3. eststo reg_`y'
            4. }

            I have to do this until var2500, how can I put 2500 variables in my xlist? I have tried using global xlist var1-var2500, but it will run a single regression instead of 2500 seperate ones.

            Comment


            • #7
              Aside from the fact that using globals is generally inadvisable for your purposes as far as I understand them, the ds command is what you are looking for:
              Code:
              ds var1-var2500
              foreach y of varlist `r(varlist)'
              ...
              }

              Comment

              Working...
              X