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

# Re: st: replicate matrix elements

 From "Brian P. Poi" To statalist@hsphsun2.harvard.edu Subject Re: st: replicate matrix elements Date Thu, 26 Jan 2012 17:17:58 -0600

```Robert Duval wrote:
```
```Hi,

Is there a command in Stata to construct a vector

A= (1,1,1,4,4,4)

out of an original vector (1,4) by replicating its elements?

In R this would be done with

rep(c(1,4), each=3, times=1)

Any suggestions will be appreciated
robert
*
```
```
One way is to use the Kronecker product with a row vector of ones whose length is the number of times you want to replicate each element.

In Mata:

: a = (1,4)
: b = J(1,3,1)
: a#b
1   2   3   4   5   6
+-------------------------+
1 |  1   1   1   4   4   4  |
+-------------------------+

Stata's older -matrix- matrix commands also use # for the Kronecker product:

. mat a = (1,4)
. mat b = J(1,3,1)
. mat c = a#b
. mat list c

-- Brian Poi
-- brian@poiholdings.com
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```