Dear Statalists,

I am a new Mata user and attempt replicating values from one column to the other in an n-dimension array.

here's are the summary of my data and code

DATA:

There is a 32142*85 dataset in MATA called psid.
The first column is id.
second to 42nd column are represent a variable called "RWH" for 41 years.
43rd to 83rd column are represent a variable called "FamNo" for 41 years.
84th column is income and 85th column is parent income.

PROBLEM:
I am trying to extract a value from column 84 through some conditions, and replicate the value to column 85.
It should be extracted a numerous of values from column 84; however column 85 is still empty.

CODE:
Code:
mata:

psid = st_data( (1::32142), ( "indivID", "RelationWithHead*",  "FamNo*", "IncomeofHead_mean", "parentinc", "test"  ) ) ;



max_sample = 32142 ;
head = 10 ;
kid = 30 ;
temp = 0 ;
RWH = ( 2::42 ) ;
FamNo = ( 43::83 ) ;


for ( n = 1; n <= max_sample; n++ )
{ 
    for ( RWH = 2; RWH <= 5; RWH++ ) 
    {
        if ( psid[ n, RWH ] == head )  
            for ( FamNo = 43; FamNo <= 46; FamNo++ )
            {
                for ( m = 1; m <= max_sample; m++ )
                {
                    if ( psid[ n, FamNo ] == psid[ m, FamNo ] )
                    {
                        if ( psid[ m, RWH ] == kid )
                        {
                            psid[ m, 85 ] = psid[ n, 84 ] ;
                        }
                    }
                }
            }
        }
        else
        { break ; }
    }
}

end
Hope anyone could help or give any advice!!

Wish you a good luck!!!