Announcement

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

  • Nested forvalue loops - referring to previous macros in a relevant macro

    Good afternoon.

    Could anyone help me decipher what syntax error I am producing in the below command sequence?

    /*Given*/
    regress offspringheight mpheight if(tallmpheight==1), robust
    global mp_b = _b[mpheight]
    global cons_b = _b[_cons]
    global new_meanmpheight1 = 68.78209

    /*Then*/
    forvalues j = 1(1)100 {
    forvalues i = `=`j'+1' {
    global new_meanmpheight`i' = $cons_b + ($mp_b * $new_meanmpheight`j')
    }
    }

    That is, I seek to perform multiple regression predictions over successive iterations that require local macro `i' to be defined in term of another local macro `j'. From that I seek to save in STATA's global memory all predictions made on the basis of the orginial regression regress offspringheight mpheight if(tallmpheight==1), robust (In attempt to demonstrate a conversion of heights).

    please let me know what mistake I am making in defining the above nested loop.
    Last edited by Joao Machado; 31 Oct 2019, 10:43.

  • #2
    First time around the loop, the inner loop becomes

    Code:
    forvalues i = 2
    and that's illegal. But you don't need a loop at all. You want 101 values based on

    intercept + slope * variable

    and there will be an expression putting those all at once into a new variable. 101 new globals? Just say no.

    Comment

    Working...
    X