Announcement

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

  • In the loop

    Loop doesn't work with $ which is a recall from global?? Thank you.

    foreach i of num 1/17 {
    global Pi2016_`i'=$Ng`i'/$NgT
    }

  • #2
    Nothing to do with looping. The problem is likely to be in combining global and local macros in the wrong way. You don't give any examples or explain what you mean by "doesn't work", but my guess is that you need

    Code:
    forval i = 1/17 {
         global Pi2016_`i' = ${Ng_`i'} / $Ngt
    }
    Other comments.

    0. You are trying to program in Stata but seemingly haven't read the basic sections on macros in [U].

    1. forval is cleaner and faster than foreach here.

    2. Much better to use variables. I will post more comments in your other thread, namely .

    https://www.statalist.org/forums/for...n-the-variable
    Last edited by Nick Cox; 31 Mar 2019, 01:34.

    Comment


    • #3
      Thank you very much!

      Comment

      Working...
      X