Announcement

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

  • Modifying vector in loop

    Hello statalist,

    I'd like to do the following in a loop (jj is defined earlier as a scalar and is an integer under 50, ADDV is a 1326 by 50 matrix but I only want to subtract column j, kk is a vector with one column and number of rows jj):

    for(j = 1; j <= jj; j++) {
    maxindex(v,1,ww=.,null=.)
    kk[j]=lookupcol[ww]
    kk[jj-j]=lookuprow[ww]
    v=v-ADDV[.,j]
    }

    This returns "<istmt>: 3301 subscript invalid" I assume due to the v replacement. I want each iteration to keep subtracting the next vector from the current v vector, thus keeping v updated through the loop.

    Intention of doing this is to remove the vector of values associated with the first maximum index value. I can't just do the second max because there are a vector of values associated with a certain maximum that I want to remove before calculating the next maximum.

    Anyone have a way of doing this?

    Thanks.

    Neal

  • #2
    Nevermind. Had a dumb issue where the loop would refer to a subscript that got calculated to zero.

    Code that works (pardon my new to mata inefficiency and creating new vars, I was just trying stuff until I got it to work now don't want to mess with it, though I'd assume those kk[oo] is unneccessary):

    for(j = 0; j < (jj/2); j++) {
    maxindex(v,1,ww=.,null=.)
    oo=j+1
    kk[oo]=lookupcol[ww]
    rr=kk[oo]
    kk[jj-j]=newlook2[ww]
    qq=kk[jj-j]
    v=v-ADDV[.,rr]
    v=v-ADDV[.,qq]
    nt=nt+1
    }

    cheers.

    Comment

    Working...
    X