Announcement

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

  • Executing Mata syntax over several dataset

    Hi all. I'm trying to execute a routine over several datasets however, it stops after the first year. The syntax is,

    local years 2003 2008 2015
    foreach i of local years {
    cd "C:/Users/Document/Data/`i'"
    use "data`i'.dta"

    putmata X=(x1 x2 x3)

    mata
    X
    hh=rows(gzero)
    X
    hh

    w=(1,2,3)
    w

    X1=X:*w
    X1

    c=rowsum(X1)

    c_md=J(hh,1,0)

    for (i=1; i<=rows(c); i++) {
    if (c[i,1] >= 3/7) {
    c_md[i,1] = 1
    }
    }

    q = colsum(c_md)

    end
    clear all

    Thanks in advance

  • #2
    Hi Mauricio.
    You just missed the } parenthesis of the foreach command.
    I wonder if the line hh=rows(gzero) will execute since I do not see that gzero was defined as matrix.

    Alberto.

    Comment

    Working...
    X