Announcement

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

  • macro within macro using foreach and forvals

    Dear Statalist,

    I would like to use a forvalues loop where one of the numerics are derived from a macro. In turn, that macro is itself derived from another macro inside a foreach loop.
    I issue all lines of code at once. Code below renders "invalid syntax". Why? Thank you. (Stata 15 on Windows).

    PHP Code:
    clear
    local cohort 1957 1958 1959
    foreach x of local cohort {
    local age 2012-`x'
    forvalues y = 52/
    `age' {
    display `y'
    }

    Last edited by Linus Andersson; 21 Aug 2018, 00:47.

  • #2
    Code:
    local age = 2012 - `x'
    To find your bug

    Code:
    display `age'
    display "`age'"
    after you calculate it.

    Comment


    • #3
      Ok, that did the trick. Perfectly clear now about the use/not use of '=' in macros. Thank you!
      /Linus
      Last edited by Linus Andersson; 21 Aug 2018, 01:33.

      Comment

      Working...
      X