Best regards,_ _# mymatrix: column1 = income, column2 = frequency
matrix mymatrix = {35, 5; 120, 5; 150, 0; 320, 6; 400, 5}
matrix result = {}loop i=1..5result |= mshape(mymatrix[i,1], mymatrix[i,2], 1)endloopprint mymatrix result_ _
_______________________________________________Am 04.08.2023 um 13:40 schrieb Artur Bala:
Hi,You can try the following script:_ _# mymatrix: column1 = income, column2 = frequency
matrix mymatrix = {35, 5; 120, 5; 150, 0; 320, 6; 400, 5}
matrix result = {}
loop i=1..5
loop mymatrix[i,2]
result = result | {mymatrix[i,1]}
endloop
endloop
print mymatrix resultThanks, Artur - for larger datasets one may want to avoid the inner explicit loop and do something like:
result |= mshape(mymatrix[i,1], mymatrix[i,2], 1)
instead. (Or using indexing: result |= mymatrix[i,1][ones(mymatrix[i,2])] -- but untested.)
I also guess that there's a clever way to avoid even the outer loop, maybe using the Kronecker product or so.
In any case, this presupposes an exact frequency table for each (discrete) occurring value, while for things like income one would probably have a kind of histogram instead with bins.
cheers
sven
Gretl-users mailing list -- gretl-users@gretlml.univpm.it
To unsubscribe send an email to gretl-users-leave@gretlml.univpm.it
Website: https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/