Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: concatenating column vectors

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: concatenating column vectors Date Sat, 31 Dec 2011 11:04:45 +0000

```This looks like elementwise division of  a matrix by a row vector and
as such is supported directly by Mata. No loop needed.

. mata
: y = (1,2,3\4,5,6\7,8,9)

: x = (1,2,3)

: y :/ x
1     2     3
+-------------------+
1 |    1     1     1  |
2 |    4   2.5     2  |
3 |    7     4     3  |
+-------------------+

Nick

On Fri, Dec 30, 2011 at 7:48 AM, Nick Cox <njcoxstata@gmail.com> wrote:
> Show us the code you tried that produced an error.
>
> Nick
>
> On Fri, Dec 30, 2011 at 7:31 AM, Jason Park <loooooo.j8311@gmail.com> wrote:
>> I want to calculate something for each column and concatenate them
>> into a matrix.
>> For a 3x3 matrix, for example, it can be done as follows:
>> matrix Q=uu`i'         /* this is directly from the code I'm using, In
>> fact, I'm trying to modify a code provided by an individual*/
>> matrix Z=vecdiag(Q)
>> matrix P=(Q[1...,1]/Z[1,1],Q[1...,2]/Z[1,2],Q[1...,3]/Z[1,3])
>> And I want to generalized this to NxN case, with and without using a
>> loop both (since it looks like the use of a loop conflicts with some
>> other part of the code, hence generates an error).