简体   繁体   English

如何连接两个向量(按列)

[英]How to concatenate two vectors (by columns)

I use the code below to concatenate two vectors in a same matrix: 我使用下面的代码将两个向量连接在同一矩阵中:

tab variable if variable <= number, matcell(x)
matrix list x   
mat a = x
mat a = a\x

However, Stata concatenates in a same column with this code. 但是,Stata将此代码连接在同一列中。

I need to concatenate it in two vectors in a same matrix making a nx2 matrix. 我需要将其连接在一个矩阵为nx2矩阵中的两个向量中。

You need to use , instead of \\ : 您需要使用,而不是\\

sysuse auto, clear
tabulate foreign, matcell(x)

matrix list x

x[2,1]
    c1
r1  52
r2  22

matrix a = x
matrix a = a , x

matrix list a

a[2,2]
    c1  c1
r1  52  52
r2  22  22

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM