有没有简单的方法可以在Stata中转置变量?
发件人:
-.48685038 -.13912173 -.91550094 -.96246505
-1.4760038 1.2873173 -.22300169 .25329232
-.01091149 -.58777297 .49454963 2.2842488
-.01376025 -.03060045 -.26231077 .32238093
.51557881 -2.1968436 .36612388 -.40590465
收件人:
-.48685038 -1.4760038 -.01091149 -.01376025 .51557881
-.13912173 1.2873173 -.58777297 -.03060045 -2.1968436
-.91550094 -.22300169 .49454963 -.26231077 .36612388
-.96246505 .25329232 2.2842488 .32238093 -.40590465
我的理解是我必须首先创建一个矩阵:
mkmat *, matrix(data)
matrix data = data'
svmat data
答案 0 :(得分:1)
尝试xpose
:
. webuse xposexmpl, clear
. list
+--------------------------------+
| county year1 year2 year3 |
|--------------------------------|
1. | 1 57.2 11.3 19.5 |
2. | 2 12.5 8.2 28.9 |
3. | 3 18 14.2 33.2 |
+--------------------------------+
. xpose, clear varname
. list
+-------------------------------+
| v1 v2 v3 _varname |
|-------------------------------|
1. | 1 2 3 county |
2. | 57.2 12.5 18 year1 |
3. | 11.3 8.2 14.2 year2 |
4. | 19.5 28.9 33.2 year3 |
+-------------------------------+
答案 1 :(得分:1)
您可以使用xpose
命令:
clear
input var1 var2 var3 var4
-.48685038 -.13912173 -.91550094 -.96246505
-1.4760038 1.2873173 -.22300169 .25329232
-.01091149 -.58777297 .49454963 2.2842488
-.01376025 -.03060045 -.26231077 .32238093
.51557881 -2.1968436 .36612388 -.40590465
end
xpose, clear
list
+-----------------------------------------------------------+
| v1 v2 v3 v4 v5 |
|-----------------------------------------------------------|
1. | -.4868504 -1.476004 -.0109115 -.0137603 .5155788 |
2. | -.1391217 1.287317 -.587773 -.0306004 -2.196844 |
3. | -.9155009 -.2230017 .4945496 -.2623108 .3661239 |
4. | -.962465 .2532923 2.284249 .3223809 -.4059047 |
+-----------------------------------------------------------+