Dear stata forum,

I am writing a paper on the causal effect of compulsory school reforms, expanding on this study (Cavaille & Marshall 2019). Inspired by their do-file, I wish to produce many regression tables/matrices at once (loop) with both multiple x's (the reforms) and multiple y's (which cohorts were affected). I can make it work when only looping the y's, but I can not make the double loop work. I get syntax error r(198) when using the following code:

Code:
local j=1
quietly foreach x in "DK (1972)" "FR (1967)" "GB (1947)" "GB (1972)" "NL (1974)" "NL (1942)" "SE (1965)" "BE (1983)" "DE-E (1959)" "IT (1963)" "GR (1975)" "PT (1956)" {
    local i=0
    matrix ALL_FS_`j' = J(6,9,0)
    matrix rownames ALL_FS_`j' = "Reform" "SE" "p-value" "Bandwidth" "Observations" "Outcome mean"
    matrix colnames ALL_FS_`j' = "(1)" "(2)" "(3)" "(4)" "(5)" "(6)" "(7)" "(8)" "(9)"
    noisily di "******************** Reform = `x' **********************"
    foreach y in eduyrs plus12 plus13 plus14 plus15 plus16 plus17 plus18 tertiary {
        local i=`i'+1
        rdrobust `y' running if reform=="`x'", c(0)
        matrix ALL_FS_`j'[1,`i'] = e(tau_cl)
        matrix ALL_FS_`j'[2,`i'] = e(se_cl)
        matrix ALL_FS_`j'[3,`i'] = e(pv_cl)
        matrix ALL_FS_`j'[4,`i'] = floor(e(h_bw))
        matrix ALL_FS_`j'[5,`i'] = e(N_l) + e(N_r)
        sum `y' if reform=="`x'" & running>=-floor(e(h_bw)) & running<=floor(e(h_bw))
        matrix ALL_FS_`j'[6,`i'] = `r(mean)'
        if `i'==1 {
            sum eduyrs if reform=="`x'" & running>=-floor(e(h_bw)) & running<=floor(e(h_bw))
            matrix ALL_FS_`j'[6,`i'] = `r(mean)'
        }
    }
    noisily estout matrix(ALL_FS_`j', fmt("3 3 4 0 0 2")), style(tex)
    local j=`j'+1
}
I am quite inexperienced when it comes to loops and matrices. Can you help me?

I am running Stata 16.1 on Mac

Best regards,
Andreas Esbjørnsen
Department of Political Science
University of Copenhagen