Thank you both, Artur and sven. Both approaches were very helpful. I
finally used:
_ _
# mymatrix: column1 = income, column2 = frequency
matrix mymatrix = {35, 5; 120, 5; 150, 0; 320, 6; 400, 5}
matrix result = {}
loop i=1..5
result |= mshape(mymatrix[i,1], mymatrix[i,2], 1)
endloop
print mymatrix result
_ _
Best regards,
jota3mc
El vie, 4 ago 2023 a las 7:15, Sven Schreiber (<sven.schreiber(a)fu-berlin.de>)
escribió:
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 result
Thanks, 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(a)gretlml.univpm.it
To unsubscribe send an email to gretl-users-leave(a)gretlml.univpm.it
Website:
https://gretlml.univpm.it/postorius/lists/gretl-users.gretlml.univpm.it/