Announcement

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

  • Stata doesn't read local macro

    Hi,
    I am trying to use macros to avoid repeating long lists of variables. The problem is that Stata doesn't read it and just skips the variables in the local macro, so all I get is a regression using only the intercept as explanatory variable. What is wrong with the code below? I cannot add the data unfortunately because of the user rights, but I hope someone can spot the error just by the code. Otherwise I will add a different example.

    Code:
    local Soc salary_eur100 age soc_eur100 SocDummy_t1 edu_* single_* status_change AntalBarn new_arrive
    xtlogit AntFlyttTot_D `Soc', i(LopNr_PersonNr) re
    Best,
    Helena

  • #2
    Seems odd as the code looks okay to me. Are you running both lines in the same session from a .do file?

    Best,
    Rhys

    Comment


    • #3
      You need to explain exactly what you are doing, and how you are executing this code. Because

      Code:
      . local Soc salary_eur100 age soc_eur100 SocDummy_t1 edu_* single_* status_change AntalBarn new_arrive
      
      . dis `Soc'
      salary_eur100 not found
      r(111);
      the error message suggest that everything is fine, Stata does not skip anything here.

      Comment


      • #4
        Hi Helena,
        As Rhys already mention. If you are running both lines separately from the do-file editor, then you will find this type of problems. (the local not being declared when you run your second line).
        When you do it from the command window (as Joro may have done), the same problem will not occur.
        For cases like this, i find it more convenient to use globals, because i use and recycle the same list of variables across specifications and summary statistics, at random times. Specially when doing data exploration.
        HTH
        Fernando

        Comment


        • #5
          Thank you guys, you're spot on - I did run them separately. And I did use globals before, which worked, but was then advised not too since it can mess things up between codes. SInce I'm really figuring out the basics of macros I think I'd better leave that for some time. Thank you all for being so helpful!

          Comment

          Working...
          X