09-07-2013 01:50 AM
I might create a matrix through a process, but I don't know its dimension beforehand. As far as I know, you can't define a matrix with some temporarily open size, right?
If so, what are some ideas to adjust for this issue?
One way is to define a matrix with sufficiently big size. Then afterwards trim by missing values or reduce the size based on some counter. For example, if you work out a matrix from other one, you allow the size based on the original matrix.
09-07-2013 05:36 AM
Right. An example of this situation is in this article: Efficient acceptance-rejection simulation - The DO Loop
Some people append to a matrix within a loop (see Pre-allocate arrays to improve efficiency - The DO Loop), but that is inefficient so I try to allocate the matrix as large as it might be, and then fill only the rows that are actually used. As you say, trim the rest, like this:
x = j(100, 1, .); /* use missing values to mark unused rows */
do i = 1 to 10;
/* do something that fills 85% of the rows */
x = remove(x, loc(x=.)); /* remove and missing values */
10-06-2013 12:17 AM
About your program mr. Wicklin, how can you remove rows based on the missing values occurring in a column?
The program you showed works for vectors, i.e. matrices of dimension n x 1.