两个列矩阵的散点图
Scatterplot of two column matrices
当A
(自变量)和B
(因变量)是大小为1 x 1000
的两个矩阵向量时,我目前在使用Stata绘制散点图时遇到问题。
我使用了命令 twoway scatter
,但是这一直失败,因为 Stata 认为 A
和 B
不是 是变量。但是,我用命令 matrix define
定义了 A
和 B
。
变量 window 是空的,我不确定为什么 A
和 B
是 而不是 变量。
示例代码:
matrix define A = [1,2,3,4,5,6,7,8,9,10]'
matrix define B = [2,3,4,5,6,7,8,9,10]'
//drawing scatterplot with A vs B and overlay a horizontal line x = 5 onto the scatterplot.
twoway scatter A B || xline(5)
我可以将矩阵声明为变量类型并保存它以便我可以在 twoway scatter
中重新使用它吗?
您需要使用svmat
命令先创建变量然后绘制图形:
clear
matrix define A = (1,2,3,4,5,6,7,8,9,10)'
matrix define B = (2,3,4,5,6,7,8,9,10)'
svmat A
svmat B
twoway scatter A B, xline(5)
Stata 中的矩阵和变量是两个不同的东西。
当A
(自变量)和B
(因变量)是大小为1 x 1000
的两个矩阵向量时,我目前在使用Stata绘制散点图时遇到问题。
我使用了命令 twoway scatter
,但是这一直失败,因为 Stata 认为 A
和 B
不是 是变量。但是,我用命令 matrix define
定义了 A
和 B
。
变量 window 是空的,我不确定为什么 A
和 B
是 而不是 变量。
示例代码:
matrix define A = [1,2,3,4,5,6,7,8,9,10]'
matrix define B = [2,3,4,5,6,7,8,9,10]'
//drawing scatterplot with A vs B and overlay a horizontal line x = 5 onto the scatterplot.
twoway scatter A B || xline(5)
我可以将矩阵声明为变量类型并保存它以便我可以在 twoway scatter
中重新使用它吗?
您需要使用svmat
命令先创建变量然后绘制图形:
clear
matrix define A = (1,2,3,4,5,6,7,8,9,10)'
matrix define B = (2,3,4,5,6,7,8,9,10)'
svmat A
svmat B
twoway scatter A B, xline(5)
Stata 中的矩阵和变量是两个不同的东西。