Hi
I have to share the following code with you.
I like oneliners or almost oneliner functions in coding.
And I like trying doing it using matrix code.
So here is how to generate a count table in Mata the matrix way:
I haven't tested it against for-loops, but simplicity in code do also count.
And actually
is a simple way of generating the dummy columns related to x
Have fun!
I have to share the following code with you.
I like oneliners or almost oneliner functions in coding.
And I like trying doing it using matrix code.
So here is how to generate a count table in Mata the matrix way:
Code:
: uniformseed(1234)
: x = round(uniform(20,1) * 10, 1) // The data
: y = uniqrows(x) // Get the unique values of x
: y, rowsum(J(rows(y), 1, x') :== y) // And now the count table
1 2
+---------+
1 | 1 5 |
2 | 3 5 |
3 | 4 2 |
4 | 5 2 |
5 | 6 1 |
6 | 7 2 |
7 | 9 3 |
+---------+
And actually
Code:
(J(rows(y), 1, x') :== y)'
Have fun!


Comment