Announcement

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

  • A question on macro expression.

    If we want to write i = i + 1, we could use ++i.

    I wonder if there is also a short expression for i = i + 2 (or any number > 2)?

  • #2
    I do not think that such a thing exists, and I do not see why you would need such a thing.

    You can check yourself, these are called macro "expansion operators" and the procedure of applying those to macros is called "incrementing a macro". (I think.)

    Comment


    • #3
      This article here "Speaking Stata: Problems with lists" by Nick Cox has a discussion on macro incrementing and decrementing:

      https://ageconsearch.umn.edu/bitstre...art_pr0009.pdf

      Comment


      • #4
        #1 Short answer is no. Some languages have such short-cuts, but not Stata or Mata.

        Comment


        • #5
          If I restate the question in post #1 as wanting to eliminate a line of code thusly
          In writing code, I can replace
          Code:
          local i = `i' + 1
          ..... `i' ....
          with
          Code:
          ..... `++i' ....
          Is there a similar shortcut when adding some number other than 1?
          I can then suggest using the expression macro expansion operator
          Code:
          ..... `=`i'+42' ....

          Comment

          Working...
          X